Re: [Help-bash] `set -v` difference in () vs not in ()
From:
João Eiras
Subject:
Re: [Help-bash] `set -v` difference in () vs not in ()
Date:
Sun, 10 Jun 2018 01:13:59 +0200
On 10 June 2018 at 00:32, Peng Yu <address@hidden> wrote:
> Hi,
>
> -v Print shell input lines as they are read.
>
> `set -v` behave differently whether it is in () or not. It seems that
> is not documented. Why is it defined so?
You need to know how bash parses files.
Bash will read one line of input and execute, and move to the next line.
So, in the second example "set -v" is read and executed, and then the
"echo" is executed.
But, when bash finds a code block, started by a bracket or
parenthesis, bash first reads the whole block and then executes.
So, it'll read "(set -v ; echo ...)" and then execute, so "set -v"
will be set AFTER the input is read.
If you set "set -v" at the top of the script, then the "(set -v...)"
block will be output.