Date:        Thu, 23 May 2024 09:04:48 -0400
    From:        Chet Ramey <chet.ra...@case.edu>
    Message-ID:  <d7b7717e-794f-4447-a2df-894caf0f0...@case.edu>


  | The bash output clearly tells you the
  | order of operations, which is the whole purpose of -x.

But it can be horribly misleading.   Consider what bash does with
this similar case (I used 5.3a1 but I suspect any version would do)

bash-5.3a1 -xc 'a=a b=b; a=1 b=2 cat /dev/null; echo $a'
+ a=a
+ b=b
+ a=1
+ b=2
+ cat /dev/null
+ echo a
a

versus

bash-5.3a1 -xc 'a=a b=b; a=1 b=2; cat /dev/null; echo $a'
+ a=a
+ b=b
+ a=1
+ b=2
+ cat /dev/null
+ echo 1
1

The only difference in the two outputs from -x is the arg to the echo
command at the end, no indication at all why they're different.


On the other hand:

sh -xc 'a=a b=b; a=1 b=2 cat /dev/null; echo $a'
+ a=a b=b
+ a=1 b=2 cat /dev/null
+ echo a
a

sh -xc 'a=a b=b; a=1 b=2 ; cat /dev/null; echo $a'
+ a=a b=b
+ a=1 b=2
+ cat /dev/null
+ echo 1
1

and it is quite clear what is happening.

Personally I'd think it more likely that your average reader would
interpret "a=1 b=2" as being executed left to right than that they'd
somehow guess that "a=1" isn't really happening in shell environment.

kre


Reply via email to