In a bash script, I need to pass a parameter to another program. The parameter has spaces in so must be quoted. Everything works fine in this simple case 1:
/bin
Use an array; this is why they were introduced.
FOO="ghi"
# Contains one element, but not the literal quotes
DEFAULTS=(--param="abc def $FOO")
# command gets 1 argument, the single element of the array
/some/command "${DEFAULTS[@]}"
# Two elements
DEFAULTS=(--param="abc def $FOO" --other="foo bar")
# command gets 2 arguments
/some/command "${DEFAULTS[@]}"