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: Peng Yu
Subject: Re: [Help-bash] Why time does not take environment variable?
Date: Mon, 26 Nov 2018 17:15:21 -0600

> > It seems that `time` is special in the aspect of whether an inline
> > environment variable can be set or not. Is it documented somewhere in
> > the manual? Thanks.
>
> You're looking at it the wrong way.
>
> The bash manual documents `time' as a reserved word. Reserved words are not
> documented as being able to be prefixed with assignment statements -- they
> are not recognized as reserved words unless they are the first word in a
> simple command. If they have to be the first word, there can be no words,
> like assignment statements, preceding them.

OK. I see. `time` is different from other commands (like `help`) in
the sense that it can recognize things like "|".

 [time [-p]] [ ! ] command [ [|||&] command2 ... ]

I can see that environment variables cannot be set for other reserved
words, like `while`.

$ TIMEFORMAT=%R while true; do time sleep 1; break; done
-bash: syntax error near unexpected token `do'

However, had bash allowed such syntax, would it causes any conflict to
other bash language syntaxes. If it would not, why not allow setting
environment variables before reserved words? Thanks.

-- 
Regards,
Peng



reply via email to

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