bug-bash
[Top][All Lists]
Advanced

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

Re: Why does -v not work until after "}" in scripts?


From: Greg Wooledge
Subject: Re: Why does -v not work until after "}" in scripts?
Date: Mon, 30 Jul 2012 12:16:06 -0400
User-agent: Mutt/1.4.2.3i

On Tue, Jul 31, 2012 at 12:12:42AM +0800, jidanni@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

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