$@ when double quoted("$@") expands to "$1" "$2" "$3" ...
There seems to be no easy way to print quoted form of what is inside "$@"
$ set -- "one two" three
$ echo "$@"
one two three
What I am looking for is, output of
'one two' three
Using 'set -x', does echo quoted form of arguments inside "$@"
$ set -x; echo "$@"; set +x
+ set -x
+ echo 'one two' three
one two three
+ set +x
User defined variable $DOLLAR_AT contains same things inside it, as what "$@" contains
$ DOLLAR_AT="'one two' three"
Dumping out, what is inside $DOLLAR_AT, using 'echo' works as expected
$ echo $DOLLAR_AT
'one two' three
due to some kind of automatic quoting by the shell of arguments that contain special characters
$ set -x; echo $DOLLAR_AT; set +x
+ echo ''\''one' 'two'\''' three
+ set +x
It is not clear why
$ echo "$@"
does not produce same output as
$ echo "$DOLLAR_AT"
When starting a command from a shell script using received "$@", there is a need to print out what is inside "$@" in a quoted form before invoking the command.
There is a similar need in printing out command line arguments passed from a bash array.
$ CMDARGS=("one two" "three")
Evaluating the array within double quotes does not print array elements in a quoted form
$ echo "${CMDARGS[@]}"
one two three
I also need a compact way to print what is in $CMDARGS[@] in a quoted form similar to what comes out of this iteration
$ for ARG in "${CMDARGS[@]}"; do echo \'$ARG\'; done
'one two'
'three'