I have a complicated bash command with some of the arguments enclosed in double quotes. When I print the command however it removes the double quotes.
I know I can use the backslash \"
but its just unseemly code and error prone in long commands.
Simple example:
#create folder with spaces
mydir="with space"
mkdir "${mydir}"
cmd="ls -lsa "${mydir}""
echo ${cmd}
# Wrong Output: ls -lsa with space
#now add \ before quotes
cmd="ls -lsa \"${mydir}\" "
echo ${cmd}
# Correct output: ls -lsa "with space"
Is there some other trick I can use to basically evaluate ${variable} in a string but keep the double quotes around it without resorting to using backslashes.