Re:Things I Wish I'd Known About Bash
by brianlund on Monday January 08, 2018 @07:45AM
(#16096331)
I wasted a lot of time on this one:
If you declare a local variable and set it in the same step e.g: local MYVAR = $(/bin/false)
The return code you get is from the local declaration, not assigning a value to the variable. It can be quite confusing when you afterwards check the return code with $? and it returns 0. Avoid it by assigning the value in a seperate command.
If you declare a local variable and set it in the same step e.g: local MYVAR = $(/bin/false) The return code you get is from the local declaration, not assigning a value to the variable. It can be quite confusing when you afterwards check the return code with $? and it returns 0. Avoid it by assigning the value in a seperate command.