Skip to content

Instantly share code, notes, and snippets.

@nvgoldin
Created April 18, 2017 07:08
Show Gist options
  • Save nvgoldin/47187bbe4ebe107f7b9f67c2e6cfc6b1 to your computer and use it in GitHub Desktop.
Save nvgoldin/47187bbe4ebe107f7b9f67c2e6cfc6b1 to your computer and use it in GitHub Desktop.
bash local variables and assignment in the same line masking the return code [SC2155]
> cat local.sh
#!/bin/bash -x
function test1() {
echo "test1"
local kk=$(wtf)
echo $?
}
function test2() {
echo "test2"
local kk
kk=$(wtf)
echo $?
}
test1
test2
> ./local.sh
+ test1
+ echo test1
test1
++ wtf
./local.sh: line 5: wtf: command not found
+ local kk=
+ echo 0
0
+ test2
+ echo test2
test2
+ local kk
++ wtf
./local.sh: line 12: wtf: command not found
+ kk=
+ echo 127
127
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment