Greg Wooledge wrote in
 <zk57gsgiubfkw...@wooledge.org>:
 |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'

Only to note that this is not portable.
The FreeBSD shell will not assign "b" to "c" for this one!

 |> 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.
 --End of <zk57gsgiubfkw...@wooledge.org>

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)

Reply via email to