Skip to content

Instantly share code, notes, and snippets.

@igricart
Created November 19, 2020 14:52
Show Gist options
  • Select an option

  • Save igricart/7abcd6d65edb77cc3353110dcc5b156d to your computer and use it in GitHub Desktop.

Select an option

Save igricart/7abcd6d65edb77cc3353110dcc5b156d to your computer and use it in GitHub Desktop.
How to check if a command succeeded or not

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment