Created
April 18, 2017 07:08
-
-
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]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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