bug-bash
[Top][All Lists]
Advanced

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

Re: Document that set -v inside case statements is special


From: Greg Wooledge
Subject: Re: Document that set -v inside case statements is special
Date: Tue, 20 Apr 2021 14:36:21 -0400

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.



reply via email to

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