Shellcheck approved way to pass 2 arguments in one variable, to a command in a bash script
7
votes
4
answers
2498
views
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
](https://www.shellcheck.net/) 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
?
Asked by Amandasaurus
(1336 rep)
May 18, 2022, 09:15 AM
Last activity: May 19, 2022, 04:16 PM
Last activity: May 19, 2022, 04:16 PM