2

Why does in the second case, the value is not used by the command followed?

$ x=1
$ echo $x
1
$ x=2 echo $x
1
subtleseeker
  • 4,415
  • 5
  • 29
  • 41
  • See [this answer](https://stackoverflow.com/a/30984437/10248678) for an in-depth explanation. – oguz ismail Jan 27 '21 at 11:25
  • Does this case has the same reason: Execute a script having `echo $x` like `x=1 bash script.sh`? Coz this also gives the output as 1. Though comparing x with 2 in the script computes out as true. – subtleseeker Jan 27 '21 at 11:31
  • Can't reproduce on bash 5.0 and bash 5.1 here. It prints `2` and `2`. – oguz ismail Jan 27 '21 at 11:44
  • 1
    Yeah, I tried it again, and its indeed 2 and 2. Not sure, what was different that time. Will re-edit the question to remove this part for future viewers. – subtleseeker Jan 29 '21 at 04:51

0 Answers0