On Tue, Apr 20, 2021 at 11:07:51PM +0800, 積丹尼 Dan Jacobson wrote:
> Please document on the man page somewhere that set -v, +v inside case
> statements is special:
> $ cat A
> case x in x)
>             set -v
>             : B
>             case y in y)
>                          set -v
>                          : Z
>                          ;;
>             esac
>             ;;
> esac
> : C
> $ bash A
> : C
> 
> I.e., -v and +v in case statements are remembered, but only have effects
> after leaving all case statements. Unlike +x, -x. Same it turns out for 
> dash(1).
> Bash 5.1.4.

It's nothing to do with 'case' specifically.  You simply don't understand
what set -v actually does.

Unlike set -x, set -v reports when bash *reads* a line of input from the
script.  Not when it runs said line.

With case, or any other compound command, the entire compound command is
read from the script and parsed, before bash can start running it.  So, by
the time the set -v is executed, the entire case command has already been
read.

The next time bash reads a command is : C, so that's what set -v reports.

  • Document t... 積丹尼 Dan Jacobson
    • Re: D... Greg Wooledge
      • R... Dmitry Goncharov via Bug reports for the GNU Bourne Again SHell
        • ... Greg Wooledge

Reply via email to