在tcsh中回显嵌套的引号 [英] echo nested quotation marks in tcsh

查看:181
本文介绍了在tcsh中回显嵌套的引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成文本文件的tcsh脚本.文本文件中的行之一是:

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.

命令是:

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

我如何转义bar bar bar周围的引号,以便正确打印它们?

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

推荐答案

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

或者这个:

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

这些应该适用于您给出的简单示例,但可能对您实际要执行的操作没有帮助...用tcsh引用总是让我很烦,特别是在尝试使用混合反引号来定义别名时,引号和双引号.

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.

请注意,第二种形式适用于echo,但实际上它在命令行上创建了三个单独的参数,它们是(在解释了转义序列之后):

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"':等,等等;

第一种形式是您应该使用的形式.

The first form is the one you should use.

这篇关于在tcsh中回显嵌套的引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆