On 06/01/2022 10:47, Matt wrote:

  > - In your examples variable values are simple. Often it is safer to add
  > double quotes around variable or command expansion. I would consider
  > adding quotes just to encourage people to do the same by default with

I appreciate these clarifications. Admittedly, I'm not great with
shell scripting.  Your recommendations appear sound to me and I've tried
to incorporate them.

I think, to illustrate unset variable escaped quotes were appropriate. Sorry that I was not clear enough.

   echo "X was set to \"$X\""

One more case where it is better (at least from my point of view) to add quotes even though they are not strictly necessary since command output contains single word and multiple words are interpreted by echo in the same way:

   echo "$(cut -f 1 -d "/") rocks!"

The updates have been made and are pushed. Thanks for your feedback!

Thank you, text is more clear now. However first time I read it with more attention.

I forgot to suggest you the following tool that catches more problems than execution the script with "-n" option:

echo 'a=2; echo "$(($a * 2))"' | shellcheck -s sh -

In - line 1:
a=2; echo "$(($a * 2))"
              ^-- SC2004: $/${} is unnecessary on arithmetic variables.

For more information:
https://www.shellcheck.net/wiki/SC2004 -- $/${} is unnecessary on arithmeti...


Reply via email to