On 10/31/14 2:01 PM, b...@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    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/

Reply via email to