1

Could someone please let me know what does it mean when I type $? in Unix?

root@kb:~# echo $?
127

root@kb:~# wc -l

root@kb:~#

root@kb:~# echo $?

130
  • 3
    See man bash. $? is the exit code of the last executed foreground pipeline (e.g. a simple command). – choroba Feb 10 '17 at 23:19
  • Thank you. so just curious to know what does 130 or 127 mean and how this helps to a system admin? When I tried I got this. example - for ls command it is always coming 0 for rm command it is always coming 1 – Pankaj Kumar Feb 10 '17 at 23:26
  • It's the return value for the previously run command perhaps. – Pimp Juice IT Feb 10 '17 at 23:26
  • You'll have to check the man page for each command to determine what the exit status means. In general, zero means success and non-zero means some kind of failure. – glenn jackman Feb 11 '17 at 0:40
  • searching for "what is $? in linux" gives you tons of answers right on the first page. duplicates: Meaning of $? in shell scripts, What is $? in bash? – phuclv Feb 11 '17 at 4:39
4

As the comments say, "$?" holds the return status code from the last command executed. Each command is free to return whatever value it wants, and those values mean whatever they say in the man page for that particular command, but in general, most unix commands return zero (0) on successful completion, and various non-zero (usually positive) numbers to indicate a variety of exit conditions.

A few sample "special" exit codes can be found here:

http://www.tldp.org/LDP/abs/html/exitcodes.html

  • Really, the core information in this answer was communicated in the comments in the question above. Yet, the answer is accurate, and provides a good resource that is worthy of recommending. Good job, +1. – TOOGAM Feb 11 '17 at 3:25
  • great information and must be shared such things – Pankaj Kumar Feb 15 '17 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.