What does $? return?

Showing Answers 1 - 27 of 27 Answers

Muthu

  • Jun 2nd, 2005
 

Will return the status of the command which is executed lastly. 
0 => Success 
2 => Error

Guest

  • Feb 27th, 2006
 

$? will return exit status of command .0 if command gets successfully executed ,non-zero if command failed.

  Was this answer useful?  Yes

Rajeesh

  • Mar 28th, 2007
 

it will return the exit status of the last command that executed.. 0 means last command was a success and 1 or any other no means it was a failure.thats it...

  Was this answer useful?  Yes

Chiranjeevi Manne

  • Mar 30th, 2007
 

It returns the exit status of the previously executed command.

if it is '0' then success otherwise fail.

  Was this answer useful?  Yes

andy

  • Jan 28th, 2012
 

UNIX commands (well the "well behaved" ones) give a return code between 0 and 127 (inclusive). General convention is that a return code of 0 (zero) indicates success and that a non-zero return code indicates a problem.

However, some commands, e.g. grep, have a convention that 0 means a match was found, a return code of 1 means no match was found and a return code of 2 or higher means some sort of error occurred like not being able able to open a file.

Really funcky return codes from the fsck command work on bitwise operations. Read the the manual folks!

  Was this answer useful?  Yes

Mo

  • Apr 20th, 2012
 

$? returns the status of the last command executed . if the last command is successfull then it will 0 , otherwise it will retrun non-zero. ex: date ; echo $? or try this dte ; echo $?

  Was this answer useful?  Yes

nitin

  • Mar 2nd, 2013
 

It gives exit status with echo command
Ex:- echo $?

It gives Zero when command is successfully executed otherwise it will gives garbage value.

  Was this answer useful?  Yes

vishesh

  • May 28th, 2013
 

$? - it returns exit status for the last executed command.

0 -> the command executed successfully
non - zero- > the commnad didnt executed successfully

  Was this answer useful?  Yes

saravanan

  • Jul 9th, 2013
 

It gives exit status of the command.

Use echo $? to get exit status of the script

Hint : if you get 0 then success, 1 means failure and some outputs

  Was this answer useful?  Yes

Kantha

  • Sep 18th, 2013
 

$? :- provide exit status of last executed command

In case the last command successfully executed then the value is 0 , if its failed to execute then the value non-zero.

Example:
$echo "Successful Line"
$echo $?
0

Example:
$echp "Successful Line"
$echo $?
-1

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions