Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does '$?' mean in a shell script?

Tags:

shell

unix

I came across a shell script that contains a statement like,

if [ $val -eq $? ]

What does $? mean here?

like image 502
Raj Avatar asked Oct 05 '12 07:10

Raj


People also ask

What does _ mean in shell script?

$_ $_ (dollar underscore) is another special bash parameter and used to reference the absolute file name of the shell or bash script which is being executed as specified in the argument list. This bash parameter is also used to hold the name of mail file while checking emails. $@

What does $@ mean in shell script?

$@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.

What does $? Mean in bash script?

echo $? - Gives the EXIT STATUS of the most recently executed command . This EXIT STATUS would most probably be a number with ZERO implying Success and any NON-ZERO value indicating Failure. ? - This is one special parameter/variable in bash.


1 Answers

I found that the link is very useful and is the great answer. It includes clearly expression with sample.

enter image description here

like image 125
biolinh Avatar answered Sep 16 '22 11:09

biolinh