Which of the quotation marks in this shell script are unnecessary?
foo &
foopid="$!"
while kill -0 "$foopid"
do
message="`foostatus`"
if test "$message" = "Terminated"
then
exit 0
else
echo foo status: $message
fi
done
exit 0
A few notes:
a) "$!"
Answer: Unnecessary. The process ID is a simple number, no funny characters.
b) "$foopid"
Answer: Again unnecessary. We know that this has the value of a previous access to "$!", so it's going to be just a number.
c) "`foostatus`"
Answer: Necessary. The status may contain spaces, wildcards, anything; and we want it all to go into the variable 'message' without further interpretation.
d) "$message"
Answer: Necessary. Without the quotes, the message will be re-parsed, and if it contains spaces (which the example suggests it usually will), it will occupy multiple arguments to test, and test will give a syntax error.
e) "Terminated"
Answer: Unnecessary. All of the characters in the string are letters. The quotation marks don't do anything because there are no special characters to suppress the interpretation of.