If I understand correctly, the syntax
Var=<something> command
should run the command after setting Var to "something". Then why does "A=3; A=4 echo $A"
produces 3 in my bash?
Variables in bash are evaluated before execution starts and not during execution, so we have a preprocessing stage for the command:
A=4 echo $A
$A
is evaluated to the current value of A
and replaces it before the execution to:
A=4 echo 3
and only then it is executed, A
changes value to 4, and 3 is printed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With