I am trying to construct the following command from a bash script:
>> mycommand -opt "third_party_app, 'app_option_a', 1"
However, when I constructed the command in a bash script like the following:
app_option="app_option_a"
app_option_val=1
tmp1='"third_party_app, '
tmp2="'${app_option}', ${app_option_val}"
tmp3='"'
optval="$tmp1$tmp2$tmp3"
echo $optval # to show that $optval looks right
command=(mycommand -opt $optval)
"${command[@]}"
I got the following command line output:
>> "third_party_app, 'app_option_a', 1"
>> + mycommand -opt '"third_party_app,' ''\''app_option_a'\'',' '1"'
I kind of get that why a pair of single quote is put around the content of $optval in the prompt output, but I am completely thrown off by all the added single quotes and back slashes in $optval's content. I know I am missing some fundamentals, so please point me in the right direction.
I have read this post and this post, they are helpful but don't give a solution to how a command argument can be constructed within a pair of double quotes, like command "argument that needs to be in double quotes"
. Instead, their answers only lead to command 'argument that needs to be in double quotes'
.