bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TIMEFORMAT in time ( )


From: Chet Ramey
Subject: Re: TIMEFORMAT in time ( )
Date: Wed, 19 Oct 2016 09:33:11 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

On 10/16/16 6:01 PM, isabella parakiss wrote:
> $ cat myscript
> TIMEFORMAT=foo var=x
> 
> time ( TIMEFORMAT=bar var=y )
> echo "<$TIMEFORMAT> <$var>"
> 
> f() { TIMEFORMAT=f; time :; }
> time ( f )
> echo "<$TIMEFORMAT>"
> 
> 
> $ bash myscript
> bar
> <foo> <x>
> f
> f
> <foo>
> 
> 
> 
> setting TIMEFORMAT in ( ) affects time out of the subshell
> this cannot be right

The difference is that `time' is not a command or a builtin; it is a shell
reserved word that sets a property of the command following it.  In this
case, that means that the timing information is printed -- in the command's
context -- after it completes.  That's why the timing property accompanies
a command, like the subshell, when it is executed, and why the code is
ordered the way it is.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]