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
>/dev/null before the last command in a pipeline. That can even make sense. The point is that > doesn't create a pipeline.
false > /dev/nulland see that only${PIPESTATUS[0]}has a value and${PIPESTATUS[1]}is null which says the entirebar > /dev/nullis a single command with no pipe involved.