echo tcsh 中的嵌套引号
我有一个生成文本文件的 tcsh 脚本。 文本文件中的其中一行是:
bla bla bla 'foo foo foo "bar bar bar"': etc etc;
注意嵌套的 '
和 "
以及 :
和 ;
很难转义
引号。
:
和 ;
要求整个字符串用引号引起来,但是,如果我这样做,就 命令是:
echo "bla bla bla 'foo foo foo "bar bar bar"': etc etc;" >> outfile
如何转义 bar bar bar
周围的引号,以便正确打印?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者这样:
这些应该适用于您给出的简单示例,但可能对您实际想要做的事情没有帮助...在 tcsh 中引用总是让我恼火,特别是在尝试使用反引号混合定义别名时,引号和双引号。
请注意,第二种形式适用于 echo,但它实际上在命令行上创建了三个单独的参数,它们是(在解释转义序列之后):
您应该使用第一种形式。
or this:
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):
The first form is the one you should use.