bug-bash
[Top][All Lists]
Advanced

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

Re: Odd bash behaviour with time:


From: Chet Ramey
Subject: Re: Odd bash behaviour with time:
Date: Sat, 01 Nov 2014 12:38:36 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

On 10/31/14 2:01 PM, bugs@m8y.org wrote:
> $ time;
> 
> real    0m0.000s
> user    0m0.000s
> sys     0m0.000s
> $ time;ls
> bash: syntax error near unexpected token `ls'
> $ /usr/bin/time;/bin/ls Usage: /usr/bin/time [-apvV] [-f format] [-o file]
> [--append] [--verbose]
>        [--portability] [--format=format] [--output=file] [--version]
>        [--quiet] [--help] command [arg...]
> 
> It's the 2nd one that surprises me.
> Why would time; succeed but time;anything fail  ?

In bash, `time' is a reserved word, not a builtin command.  It precedes a
pipeline and modifies its behavior.  That's what allows it to time
pipelines and command blocks.  A useful hint about whether or not `time'
appears in a valid place is to see whether the command would be valid if
`time' weren't present.

There is a special grammar production that allows time to appear by itself
on a line and time an empty command (`timespec list_terminator').  I put it
in for bash-3.1 over ten years ago.

Posix conformance isn't really a consideration: Posix requires that `time'
be followed by something.  Bash does do some special things with timing
null commands in Posix mode, though -- the `R' format specifier in
TIMEFORMAT is a measure of how many seconds have elapsed since the shell
was invoked.  The details are in execute_cmd.c:time_command().

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



reply via email to

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