3

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?

Mike
  • 53

1 Answers1

3

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 \ [ * ?.

dr_
  • 29,602