help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Why time does not take environment variable?


From: Greg Wooledge
Subject: Re: [Help-bash] Why time does not take environment variable?
Date: Mon, 26 Nov 2018 14:38:11 -0500
User-agent: NeoMutt/20170113 (1.7.2)

On Mon, Nov 26, 2018 at 01:31:43PM -0600, Peng Yu wrote:
> Hi,
> 
> I thought that the first TIMEFORMAT set the environment variable for
> `time` temporarily. But it apparently has no effect. Could anyone help
> me understand why it is so? Thanks.
> 
> TIMEFORMAT=%3R time sleep 1
>         1.00 real         0.00 user         0.00 sys
> export TIMEFORMAT=%3R
> time sleep 1
> 1.018

Because there are TWO different time commands: one is external (probably
in /usr/bin/) and the other is a special bash keyword, which is like
a builtin with extra voodoo powers.

If you just run "time mycmd", you are using bash's keyword.  But if you
stick a variable assignment in front of it, then you are using the
external one.

wooledg:~$ time sleep 0.1
real 0.102  user 0.004  sys 0.000

wooledg:~$ x=y time sleep 0.1
0.00user 0.00system 0:00.10elapsed 0%CPU (0avgtext+0avgdata 1836maxresident)k
16inputs+0outputs (1major+72minor)pagefaults 0swaps



reply via email to

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