echo nested quotation marks in tcsh

时光怂恿深爱的人放手 提交于 2019-12-10 15:59:39

问题


I have a tcsh script that generates a text file. One of the lines in the text file is:

bla bla bla 'foo foo foo "bar bar bar"': etc etc;

Note the nested ' and " and also the : and ; that must be there.

The : and ; require the whole string to be surrounded by quotation marks. However, if I do that, I have trouble escaping the quotation marks.

The command is:

echo "bla bla bla 'foo foo foo "bar bar bar"': etc etc;" >> outfile

How can I escape the quotation marks around bar bar bar so that they get printed correctly?


回答1:


echo "bla bla bla 'foo foo foo "\""bar bar bar"\""': etc etc;"

or this:

echo "bla bla bla 'foo foo foo "\"bar bar bar\""': etc etc;"

These should work for the simple example you gave, but may not help for what you're actually trying to do... Quoting in tcsh always annoyed me, especially when trying to define aliases with a mix of back-ticks, quotes, and double-qutes.

Be warned that the second form works for echo, but it actually creates three separate arguments on the command line, which are (after interpreting the escape sequences):

  • bla bla bla 'foo foo foo "bar
  • bar
  • bar"': etc etc;

The first form is the one you should use.



来源:https://stackoverflow.com/questions/954390/echo-nested-quotation-marks-in-tcsh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!