The bash manual says "The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments".
I also understand that exported variables are by default passed to subprocesses that bash creates.
I'm testing some behaviours with non-exported variables, and what I don't understand is how it works when the assignments are followed by the ;
operator, and then some other commands are executed.
My case is the following:
VAR=hello; echo $VAR
prints "hello".
VAR=hello :; echo $VAR
prints a newline.
VAR=hello; echo $VAR; bash -c 'echo $VAR'
prints "hello" and a newline.
The question is, in the first and third command, why is VAR being expanded? They are different commands, with (apparently) no parameter assignments prefixed.
I've tried in bash 4.4.20 and 5.1.16, having the same behaviour on both.
$VAR
, it'd be impossible to use unexported variables for pretty much anything.VAR=hello command-that-uses-VAR
. The variable assignment is not separated from the command with a seicolon.