Answer the question
In order to leave comments, you need to log in
How to suppress the output of a function while still receiving a return code?
Good day.
I have a custom bash function like this:
superMegaFunction()
{
.................
echo "FATAL ERROR: some_text_error"
return 127
.................
return 0
}
checkMega()
{
superMegaFunction &> /dev/null
echo "Status: $?"
}
bash -x
I don't see the output " Status: %code% ". I tried the option without superMegaFunction > /dev/null
- the result is the same. return
bash, after all, in any case, it should return the code without interrupting the execution of the common script, or am I missing something?
Answer the question
In order to leave comments, you need to log in
everything works fine, for example:
f(){
if
then echo "ok"
return 0
else echo "error"
return 1
fi
}
check_f(){
f &> /dev/null
echo "Status: $?"
f ww &> /dev/null
echo "Status: $?"
}
check_f
Status: 1
Status: 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question