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 [email protected] http://cnswww.cns.cwru.edu/~chet/