Debugging Shell Scripts -Quiz Results

The answers you selected are indicated below, along with text that explains the correct answers.

1. Which of the following commands resets the trap for signal 2 back to normal system behavior?
Please select the best answer.
  A. trap 2
  B. trap 2
  C. trap ''echo error' 2
  D. trap r 2
  B is the correct answer. B is the correct answer because this command resets signal 2. Answer A is incorrect because this will instruct the shell to ignore this signal. Answer C is incorrect because it will print 'error' whenever a user types CTRL + C. Answer D is incorrect because there is no r option to the trap command.

2. Which of the following lines of code does not contain a syntax error?
Please select the best answer.
  A.
if [ $answer =   'yes'   ]
then
  echo 'yahoo'
fi
  B.
if [ $answer ='yes'   ]
then
  echo 'yahoo'
fi
  C.
while [ '$answer' = 'yes' ]
  echo 'yahoo'
done
  D.
while ['$answer' = yes' ]
do
  echo 'yahoo'
done
  Answer A is correct; this statement has no syntax errors. Answer B is incorrect because there is no space after the equal sign. Answer C is incorrect because it is missing the keyword do. Answer D is incorrect because there is no space after the opening square bracket.

3. Which type of error is usually the easiest to spot in a shell script?
Please select the best answer.
  A. Logic
  B. Robust
  C. Syntax
  D. Run-time
  C is the correct answer. Syntax errors are generally easier to spot than other types of errors. Answer A is incorrect because logic errors are often difficult to spot. Answer B is incorrect because there is no such thing as a robust error. Answer D is incorrect because it is sometimes difficult to anticipate the input that a user might type into a program.