Most of the time I see $(command)
used, but I have also seen "$(command)"
for example:
if [ "$(command)" ]; then
stuff
fi
What is the purpose of the quotes in the second example?
Most of the time I see $(command)
used, but I have also seen "$(command)"
for example:
if [ "$(command)" ]; then
stuff
fi
What is the purpose of the quotes in the second example?
The quotes tell the shell to consider the output of command
as a whole. Without them, the script will be broken if the command's output happens to contain whitespaces or any of the special characters \
[
*
?
.