bash syntax question
I recently came across the following example for switching time zones:
$ date Fr 6. Jun 12:49:30 CEST 2008 $ TZ=UTC date Fr 6. Jun 10:49:35 UTC 2008 Could someone please explain to me the general shell syntax involved here? I did not know that I could put an assignment and a command on one line. My dull approach would have been $ echo $TZ $ TZ=UTC $ export TZ $ date Fr 6. Jun 10:54:29 UTC 2008 $ unset TZ $ date Fr 6. Jun 12:54:39 CEST 2008 Thanks in advance, Malte -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
bash syntax question
On Friday 06 June 2008 12:59, Malte Forkel wrote:
> I recently came across the following example for switching time > zones: > > $ date > Fr 6. Jun 12:49:30 CEST 2008 > $ TZ=UTC date > Fr 6. Jun 10:49:35 UTC 2008 > > Could someone please explain to me the general shell syntax involved > here? I did not know that I could put an assignment and a command on > one line. My dull approach would have been [...] The 'date' command runs in a child process for which the bash shell has to determine the environment. Parameter assignments are inherited in that environment (i.e. the 'date' command sees them) in two cases: either when the variable is not only declared but also exported or when the assignment is provided on the command line right before the command itself. From the man page: The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described above in PARAMETERS. These assignment statements affect only the environment seen by that command. For more information you may want to read the "Command execution environment" section in the Bash man page. Best regards. Alfredo -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
bash syntax question
Alfredo Finelli schrieb:
The 'date' command runs in a child process for which the bash shell has to determine the environment. Parameter assignments are inherited in that environment (i.e. the 'date' command sees them) in two cases: either when the variable is not only declared but also exported or when the assignment is provided on the command line right before the command itself. From the man page: The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described above in PARAMETERS. These assignment statements affect only the environment seen by that command. For more information you may want to read the "Command execution environment" section in the Bash man page. Alfrede, thanks for your help! No I understand. And its good to know that I'm using an official feature :-) -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
| All times are GMT. The time now is 07:52 PM. |
VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.