32

How to find the return value of last executed command in UNIX?

  • 1
    >echo $? By the way, did u really want to ask this? – pugmarx Jul 14 '09 at 05:59
  • 4
    Looks like around 25,000 people wanted to ask this. – Beejor Nov 22 '17 at 06:14
  • I think the vast majority of users will be interested in how `bash` delivers the return value of the last executed command. But it's worth mentioning that not all shells are the same. I think your question should be more specific. – Bruno Unna Jun 06 '19 at 13:25

1 Answers1

53

You can use the shell variable $?

Such as:

$ true ; echo $?
0
$ false ; echo $?
1
Carlos Robles
  • 10,828
  • 3
  • 41
  • 60
ghostdog74
  • 327,991
  • 56
  • 259
  • 343