How/Command to check the previously executed command’s status(success or not) – Unix/Linux

In some strange situations it would be more helpful for us to find the previously executed command’s status(success or not). We can figure it out by using the following command;

# echo $?

Output:

0 : The '0' represents, successfully executed command status. :-)
Any other digit : represents, the previously executed command was failed. :-(

Example:

----
[root@localhost ~]# gdgmd
bash: gdgmd: command not found
[root@localhost ~]# echo $?
127
----
[root@localhost ~]# man ls
[root@localhost ~]# echo $?
0
----

Related Links:
echo $SHELL

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

Leave a Reply

Your email address will not be published. Required fields are marked *