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
7
  • 3
    See man bash. $? is the exit code of the last executed foreground pipeline (e.g. a simple command).
    – choroba
    Feb 10, 2017 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 Feb 10, 2017 at 23:26
  • It's the return value for the previously run command perhaps. Feb 10, 2017 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. Feb 11, 2017 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, 2017 at 4:39

1 Answer 1

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

2
  • 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, 2017 at 3:25
  • great information and must be shared such things Feb 15, 2017 at 1:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .