0

I want to construct a bash script which contains nested double quotes. I've tried all of the usual tricks, in particular rprint which everybody recommends. But nothing I've tried works. In particular, rprint -v name "%q " lets me nest quotes but I then can't deal with the \'s it puts in front of the quotes. Finally I settled on this extremely crude kludge:

shCommand=`echo !ssh -p $othPort!`
execThis=`echo rsync -e $sshCommand etc etc | tr '!' '"'`
eval $execThis

Thus execThis is what I want, i.e.,

 rsync -e "ssh -p XXXX" etc etc

But there has to be a better way to do this since a) it's extremely crude and b) it won't work if I need the ! in following line --- there seems to be no special character that bash never uses. Could somebody tell me what a real bash programmer would do in this instance? Thanks very much for any advice

1
  • 1
    In my opinion that is not a good problem description. You talk about problems instead of showing the code and the output. Commented May 22, 2020 at 1:00

1 Answer 1

1
othPort=XXXX
shCommand="ssh -p $othPort"
cmdline=(rsync -e "$shCommand" etc etc)
"${cmdline[@]}"
othPort=XXXX
shCommand="ssh -p $othPort"
cmdline="rsync -e \"$shCommand\" etc etc"
eval "$cmdline"
1
  • Thanks! Such a simple solution! Commented May 23, 2020 at 16:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.