On Thu, Mar 15, 2012 at 10:18 AM, Bill Gradwohl <address@hidden> 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
> again, the set -v appears non functional.
>
> Why?
>
> Thank You
>
> --
> Bill Gradwohl
>
My guess would be that set -v works the same way shopt -s extglob
does, and actually changes the way bash parses commands.
Since bash parses compound commands at once (yes, that's the entire
case statement), the set -v won't actually take effect until after you
exit that command. Same for setting it within a function, if
statement, loop, etc.