bug-bash
[Top][All Lists]
Advanced

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

Re: sh vs. bash -xc 'a=b c=$a'


From: Greg Wooledge
Subject: Re: sh vs. bash -xc 'a=b c=$a'
Date: Wed, 22 May 2024 19:10:57 -0400

On Thu, May 23, 2024 at 06:56:01AM +0800, Dan Jacobson wrote:
> It seems these should both make one line "+ a=b c=b" output,
> 
> for s in sh bash
> do $s -xc 'a=b c=$a'
> done
> 
> I mean they give the same results, but bash splits it into
> two lines, so the user reading the bash -x output cannot tell
> if one (correct) or two (incorrect) lines were used.
> They can tell with sh -x.

Does it actually matter?  What makes bash's output "incorrect", exactly?

> By the way, I looked up and down the man page,
> and wasn't sure if it says one should expect
> $c to end up as c= or c=b in fact!

I don't know where it's documented, but assignments and expansions are
always performed left to right.  In your example, a value is assigned
to variable a before $a is expanded.

> And I'm not sure the man page says to expect two lines or one of -x
> output either, when using sh vs. bash.

I don't see why it matters.  The purpose of the -x output is to show
you what the shell is doing, so that you can debug your script.  As
long as the output is *clear*, it's doing its job.

In bash's case,

hobbit:~$ bash -xc 'a=b c=$a'
+ a=b
+ c=b

you can very easily see the order in which the assignments happen, and
the values that are assigned.



reply via email to

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