To check if a command was successfully run in our bash script, we have to check the value of its output, which is stored in the
$? variable. If its value equals to 0, then the command was successful, otherwise, an error was thrown:
rm ~/data.tar.bz2
if [ "$?" != 0 ]; then
echo "ERROR: Could not delete file"
exit 1
fi
$
in fact, you can use error code to do conditional execution of commands. For instance:
ResponderEliminarrm ~/file.tar && echo "deleted" || echo "not deleted"