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: Piotr Grzybowski
Subject: Re: Odd bash behaviour with time:
Date: Sat, 1 Nov 2014 19:10:51 +0100

Hi Chet, hi all.

 based on what you say, and some comments in parse.y ;-) isn't the
below patch enough to get rid of the parser error for "time;echo;"
case?

diff --git a/parse.y b/parse.y
index 815db98..766f258 100644
--- a/parse.y
+++ b/parse.y
@@ -1224,6 +1224,8 @@ pipeline_command: pipeline
                          /* XXX - let's cheat and push a newline back */
                          if ($2 == '\n')
                            token_to_read = '\n';
+                         if ($2 == ';')
+                           token_to_read = ';';
                        }
        |       BANG list_terminator
                        {

cheers,
pg


On Sat, Nov 1, 2014 at 5:38 PM, Chet Ramey <address@hidden> wrote:
> On 10/31/14 2:01 PM, address@hidden 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    address@hidden    http://cnswww.cns.cwru.edu/~chet/
>



reply via email to

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