bash ‘local’ directive eats status codes
Did you know that the local directive in bash returns a status
code? I didn’t.
#!/bin/bash
function return_nonzero
{
return 1
}
function main
{
v=$(return_nonzero)
echo $?
local v=$(return_nonzero)
echo $?
local v
v=$(return_nonzero)
echo $?
}
main
At runtime:
$ bash local-return-code.sh 1 0 1
At least some bugs teach you something new.