On Tue, Jul 31, 2012 at 12:12:42AM +0800, jida...@jidanni.org wrote:
> Why does -v not work until after "}" in this script?
> 
> # su - nobody
> No directory, logging in with HOME=/
> $ cat /tmp/o
> {
>     set -v
> # NO STDERR
> }
> # YES STDERR
> $ sh /tmp/o
> # YES STDERR

Because bash reads its input line by line, but also command by command.
When bash reads the { line, it knows it has to keep reading until a
matching } in order to be able to parse the entire command.  So it does
that -- it reads the entire command group into memory.

Then it executes the command group, which turns on -v.

Then it reads the NEXT command, and since -v is now in effect, it echoes
that command after reading it.

Reply via email to