I am trying to combine a set of parameters, some with spaces, in a variable for reuse many places. You cannot use echo directly as in many other online examples since that does not reveal that 3 parameters are often passed instead of two, one containing a space. This question comes close to mine: Passing arguments with spaces contained in variable in bash
Is this a problem with the bash version (Raspberry PI) I am using?
Test() { for var in "$@"; do echo "$var"; done ; }
VAL=ghi
Test abc "def $VAL"
abc
def ghi
ARGS="abc \"def $VAL\""
Test $ARGS
abc
"def
ghi"
Some things I tried without success:
ARGS="abc "\""def $VAL"\"""
ARGS=$"abc \x22def $VAL\x22"
ARGS="abc \x22def $VAL\x22"
ARGS=$"abc \"def $VAL\""
ARGS="abc \"def $VAL\""
ARGS=(abc "def $VAL")
Test $ARGS
Test ${ARGS}
Test ${ARGS[@]}