`time` crashes in a script

Bug #356624 reported by Calil Neto
2
Affects Status Importance Assigned to Milestone
bash (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

In a script, when I run `time` like this:

$TIME=`time $cmd`

It runs well, but when I put the time in a variable

cmd="time cmd"
$TIME=`$cmd`

It apparently crashes.

This is a testcase where it works:
$ cmd="ls"; time $cmd
(ls output)

real 0m0.003s
user 0m0.000s
sys 0m0.004s

And in this case it crashes:
$ cmd="time ls"; $cmd
(ls output)
0.00user 0.00system 0:00.00elapsed 200%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+292minor)pagefaults 0swaps

affects: ubuntu → bash (Ubuntu)
Revision history for this message
IKT (ikt) wrote :

ikt@ikt-desk:~$ cmd="time ls"; $cmd
Dropbox Music Templates
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+305minor)pagefaults 0swaps
ikt@ikt-desk:~$ uname -a
Linux ikt-desk 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64 GNU/Linux
ikt@ikt-desk:~$

Confirming this bug in ubuntu 9.10.

Changed in bash (Ubuntu):
status: New → Confirmed
Revision history for this message
IKT (ikt) wrote :

Talked about this on irc and Pici noted something:

Its just using the default time output format, instead of the one that it regularly uses. The manpage says that it should use the following format if none is specified:

%Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax)k
%Iinputs+%Ooutputs (%Fmajor+%Rminor)pagefaults %Wswaps

It looks like it has to do with an environment variable, but its not $TIME even though the manpage says it should be.

If I run time from within dash, it gives me that extended output.
--
So it doesn't appear to be a problem with the command as such, but it's not working as intended.

Revision history for this message
Jilles Tjoelker (jilles) wrote :

This is because bash's time is a keyword, not a builtin command ('type time' will show). Therefore it will only be recognized if it is in the input literally and unquoted.

Revision history for this message
IKT (ikt) wrote :

setting to invalid since there is essentially nothing to fix.

Changed in bash (Ubuntu):
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.