I want to check if last command failed or not in bash. I base this mini script on this
#!/bin/bash
mkdir nothere/cantcreate
echo $?
if [ $? -eq 0 ]; then
echo "command succeed"
else
echo "command failed"
fi
This prints the following:
mkdir: cannot create directory ‘nothere/cantcreate’: No such file or directory
1
command succeed
I expect it to print command failed as the value of $? is 1. Why does the equality not behave as I expect ?
Aucun commentaire:
Enregistrer un commentaire