» Linux » Examen sur Linux » Examen 201 : Advanced Administration » Section 3 » Question 3/20
3.You are creating a script with demands that the previous command execute correctly. How would you correctly test the exit status of the previous command in BASH?

if [ "$#" -eq "0" ]; then...
if [ "$?" -eq "0" ]; then...
if [ '$#' == 0 ]; then...
if [ '$?' == '0']; then...
if [ $@ -eq 0 ]; then...

Explanation: The variable "$?" checks the exit status of the last command run. The -eq "0" statement is used to check whether a condition is true. The statement if [ "$?" -eq "0" ]; then... will check that the last command executed correctly and run the next part of the script.

Reference: http://www.bolthole.com/solaris/ksh-basics.html

Incorrect Answers
A: The variable is "$?" not "$#".
C: The variable is "$?" not "$#".
D: The variable is "$?" not '$?' (double quotes, not single quotes).
E: The variable is "$?" not $@.

« Question 2 Question 4 »