1 year ago
#229872
onlycparra
Why does this bash function returns always 0?
I am constructing a wrapper function for bash 5.1 that would wake a command, and indent its output. If the command fails, then I want the wrapper to pass the command return code to the caller
indent() {
local com_out=$($* 2>&1)
local exit_code=$?
echo -e "$com_out" | awk '{ print " â" $0 }'
return $exit_code
}
However, I don't understand why it always return 0:
$ indent cp a b
âcp: cannot stat 'a': No such file or directory
$ echo $?
0
If I run the commands one at the time in my shell (zsh), replacing $*
with an actual command, I get that $exit_command
is indeed 1.
bash
function
shell
return-code
0 Answers
Your Answer