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
    In my opinion that is not a good problem description. You talk about problems instead of showing the code and the output. – Hauke Laging May 22 at 1:00
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"
| improve this answer | |
  • Thanks! Such a simple solution! – Leo Simon May 23 at 16:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.