FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 06-06-2008, 10:59 AM
Malte Forkel
 
Default 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
 
Old 06-06-2008, 12:35 PM
Alfredo Finelli
 
Default 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
 
Old 06-06-2008, 02:40 PM
Malte Forkel
 
Default 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
 

Thread Tools




All times are GMT. The time now is 06:01 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org