0

I am trying to understand how the one-time variable assignment needs to be done correctly in Bash. Please consider the following two examples, where I was expecting to get the same result in Bash:

unset Var 
Var=123 echo $Var
# prints nothing

I now edit the file test.sh with the following content:

#!/bin/bash
echo $Var 

and execute:

unset Var 
Var=123 source test.sh
# prints 123

Can somebody please explain why there is different behavior in these two examples?

Thanks!

  • you need a `;` in between the variable assignment and the `echo` for it to work – Jetchisel Apr 27 '20 at 06:30
  • 1
    @Jetchisel the change you suggest produces two different statements. The question is about the one-time environment variables used with the current statement. – axiac Apr 27 '20 at 06:45

0 Answers0