Referencing to yesterdays nugget, there’s one example I’d like to give.

With a bit more complex scripts it happens that you build commands and their paramters on the fly (meaning: during script-run-time).

And it usually works. Until it does not.

Shellcheck (see. 2017-12-05), covers that part and provides the solution as well.

The problem:

args="$para1 $para2"
args+="-s '$string_with_whitespace'"
command $args

The word splitting will kill you here and the value of the parameter -s will be separated at the whitespace in $string_with_whitespace.

The better way to do this would be this:

args=($para1 $para2 -s "$string_with_whitespaces")
command "$(args[@])"

This is less likely to break and the code is more resilient to failures.

Though when I stumbled over this a couple of weeks ago, my code seemed to work although Shellcheck complained. I read about the problem, changed the code and learned something new.