Skip to main content
2 of 3
added 4 characters in body
Steve
  • 171
  • 7

Why do bash variable assignments affect the last exit code $?

I was surprised to find out that setting an environment variable modified the last exist code variable $?:

$ false
$ echo $?
1
$ false
$ FOO=BAR
$ echo $?
0
$ 

The bash manual says only this about $?:

($?) Expands to the exit status of the most recently executed foreground pipeline.

Where is the exit code of a variable being set documented? Can it fail?

Steve
  • 171
  • 7