I have a command such that
bar > /dev/null
and I want to know the exit status of bar. I read some posts su about ${PIPESTATUS[0]} but this works when one pipes the output via | and I can't make it work with > instead.
What am I missing?
I have a command such that
bar > /dev/null
and I want to know the exit status of bar. I read some posts su about ${PIPESTATUS[0]} but this works when one pipes the output via | and I can't make it work with > instead.
What am I missing?
> isn't a command. This means that bar will be the last command executed. You can check for failure with a standard if statement:
if ! bar > /dev/null; then
echo "bar command failed"
fi
You can also access its return code with $? if you are interested in something more than zero or non-zero:
bar > /dev/null
if [ "$?" -eq 45 ]; then
echo "bar returned exit code 45"
fi