echo tcsh 中的嵌套引号

发布于 2024-07-22 21:11:39 字数 440 浏览 4 评论 0原文

我有一个生成文本文件的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月染过的梦 2024-07-29 21:11:40
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 中引用总是让我恼火,特别是在尝试使用反引号混合定义别名时,引号和双引号。

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

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

您应该使用第一种形式。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文