How to check it ? $? represents last command sent #!/bin/bash touch a/a/.a if [ $? -eq 0 ]; then echo OK else echo FAIL fi This command fails because there is no way to create this file