help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Why won't set -v work?


From: Eric Blake
Subject: Re: [Help-bash] Why won't set -v work?
Date: Thu, 15 Mar 2012 09:10:14 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1

On 03/15/2012 08:18 AM, Bill Gradwohl wrote:
> I'm experimenting and came up with something I can't explain.
> 
> #!/bin/bash
> declare parm='pass1'
> #case "${parm}" in
> #   'pass1')
>       set -v
>       if true; then echo True; fi
> #    ;;
> #   *)
> #   echo Hello
> #   ;;
> #esac
> 
> When executed, the above works as expected.
> 
> If you remove the octothorpes to activate the case statement and run it

(I'm assuming you didn't mean to remove the # from line 1 on the she-bang)

> again, the set -v appears non functional.
> 
> Why?

set -v operates on the top-level commands as they are parsed.

With the comments in place, 'set -v' is parsed, then the flag is turned
on, then 'if true; then echo True; fi' is parsed, so it is output.

With the outer case in place, the _entire_ case statement is parsed,
then 'set -v' is executed, then 'if true...fi' is executed, then the
case statement completes, then all _subsequent_ parsing is printed.

The problem is simple once you realize that the flag to output parsing
only affects what has not yet been parsed, and also realize that the
parser must find the end of any enclosing compound statement before it
starts executing any of the individual statements within that complex
statement, and that bash does not reparse subsets of an already-parsed
larger statement.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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