I would like to put this command into a file to be run later:
ln -s "$xr"/ya.txt ~ I can do that with (1):
cat > zu.sh <<eof ln -s "$xr"/ya.txt ~ eof or (2):
printf 'ln -s "%s"/ya.txt ~\n' "$xr" > zu.sh or (3):
echo "ln -s '$xr'/ya.txt ~" > zu.sh or (4):
printf 'ln -s %q/ya.txt ~\n' "$xr" > zu.sh or (5):
printf 'ln -s "%s"/ya.txt ~\n' "${xr//\"/\\\"}" however each solution is problematic. if the variable in (1) or (2) contains a double quote, they will fail; if the variable in (3) contains a single quote, it will fail. (4) is good but is not defined by POSIX. (5) is good but is a Bashism. it looks like the best option would be to use (1) or (2) and escape any double quotes in the variable, but can that be done another way?