Ah, I see.
It may be worthwhile to instead define CMD as an array, rather than a string, like this
CMD
CMD=("do_some_thing") if [[ "$USE_S_FLAG" == 1 ]]; then CMD+=("-S", "$1") fi "${CMD[@]}" "the" "rest" "of" "your" "args"
Of course at that point you’re losing some of the readability benefits of using bash in the first place...
Edit: or, of course, you keep the script simple and readable at the cost of some duplication, e.g.
if [[ "$USE_S_FLAG" == 1 ]]; then "$CMD" -S "$1" "the" "rest" "of" "your" "args" else "$CMD" "the" "rest" "of" "your" "args" fi
Ah, I see.
It may be worthwhile to instead define
CMD
as an array, rather than a string, like thisOf course at that point you’re losing some of the readability benefits of using bash in the first place...
Edit: or, of course, you keep the script simple and readable at the cost of some duplication, e.g.