Skip to main content
[Edit removed during grace period]
Link
muru
  • 78.4k
  • 16
  • 214
  • 320
Became Hot Network Question
edited title
Link
ctrl-alt-delor
  • 28.8k
  • 11
  • 66
  • 113

Shellcheck approved way to pass 2 arguments in one variable, to a command in a bash script

Source Link
Amandasaurus
  • 1.3k
  • 3
  • 15
  • 25

Shellcheck approved way to pass 2 arguments to a command in a bash script

In a bash script, I call another programme, but I want to configure that programme with a command line option. The following works:

AREA_ARG=""
if __SOME_SETTING__ ; then
  AREA_ARG=" --area us,ca "
fi

process_data -i /some/path $AREA_ARG

i.e. bash either executes process_data -i /some/path, or process_data -i /some/path --area us,ca .

However shellcheck complains!

$ shellcheck test.sh 

In test.sh line 7:
process_data -i /some/path $AREA_ARG
                           ^-------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
process_data -i /some/path "$AREA_ARG"

For more information:
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...

I understand the principle, but I want/need the variable to split on the space so that process_data gets 2 arguments.

What's the Proper Way™ to do this in bash?