LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-12-2012, 04:09 AM   #1
trunikov
LQ Newbie
 
Registered: Jul 2005
Location: Kiev, Ukraine
Distribution: rh9
Posts: 6

Rep: Reputation: 2
Cool Grouping commands in bash


Hi ALL,

I've question about grouping of commands in the bash.
For the sake of simplicity I'll show a bit artificial example but it explain the issue.
For example I can run following commands:

Code:
$ date; date
Wed Dec 12 11:52:46 EET 2012
Wed Dec 12 11:52:46 EET 2012
Excellent, but now I would like to run the same commands in different time zone:

Code:
$ TZ='Asia/Kolkata' date; date
Wed Dec 12 15:24:07 IST 2012
Wed Dec 12 11:54:07 EET 2012
Not perfect, the result is not exactly what I want. The first command executed in the specified timezone but the second one is executed in default system timezone. But I would like to run both commands in the specified timezone.
I know that bash allows grouping of executed commands like below:

Code:
$ (date; date)
Wed Dec 12 11:58:56 EET 2012
Wed Dec 12 11:58:56 EET 2012
Unfortunately in this syntax I can't specify timezone:

Code:
$ TZ='Asia/Kolkata' (date; date)
bash: syntax error near unexpected token `('
So, can anybody help me and show correct syntax of command line.

Thanks.

P.S. I know that I can export variable TZ to environment and then execute commands from the example, but I want to find out how to do that with help of a single command line
 
Old 12-12-2012, 04:34 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
This ?
Code:
(export TZ='Asia/Kolkata' && date && date)
creates a subshell, so your parent shell retains orig TZ (if that's what you want)
 
1 members found this post helpful.
Old 12-12-2012, 04:39 AM   #3
trunikov
LQ Newbie
 
Registered: Jul 2005
Location: Kiev, Ukraine
Distribution: rh9
Posts: 6

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by chrism01 View Post
This ?
Code:
(export TZ='Asia/Kolkata' && date && date)
creates a subshell, so your parent shell retains orig TZ (if that's what you want)
Hi chrism01,

Thank you very much. Your answer give me right direction to write what I want:

Code:
$ (TZ='Asia/Kolkata'; date; date)
Wed Dec 12 12:36:43 EET 2012
Wed Dec 12 12:36:43 EET 2012
Many thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH script question - grouping conditions in brackets? FireRaven Linux - General 2 03-08-2012 06:38 PM
Where are BASH commands stored? Not scripts but what bash exe uses. theKbStockpiler Programming 11 02-23-2011 03:06 PM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
Running bash but common bash commands not working michellepace Linux - Newbie 11 07-17-2010 09:19 AM
bash - while + until loops grouping? trees Linux - General 2 02-19-2004 02:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration