How do I display the exit status of the last command in bash?
-
Man page for bash - GNU Bourne-Again SHell
Commands that complete without errors exit with a status of number zero meaning it completed successfully and without issues. For example:
$ pgrep systemd 1 635 667 828 926 1328 2237
Check the exit status immediately after.
echo $? 0
If the command does not complete successfully the exit status will be non-zero. Here the number one exit status number, means, No processes matched or none of them could be signalled.
$ pgrep systemddd $ echo $? 1
You would expect this as there is no such command systemddd and pgrep could not find it.
© Lightnetics 2024