使用 tcsh 别名转义双引号
我正在尝试运行以下命令:
replace -x "must " A2input.txt
replace -x " a" -f -s ## A2input.txt
replace -x to -s ## -a A2input.txt
replace -x faith -f "unequivocal" A2input.txt
如果我可以将其别名为简短的名称,例如“a”、“b”、“c”、“d”等,那就太好了...
但是,其中一些参数带有引号,这会弄乱别名。 有谁知道如何真正转义双引号? 我已经尝试过诸如 '\"' 和 \" 之类的东西,但似乎没有任何效果。
我使用 tcsh 作为我的 shell。
I'm trying to run the following commands:
replace -x "must " A2input.txt
replace -x " a" -f -s ## A2input.txt
replace -x to -s ## -a A2input.txt
replace -x faith -f "unequivocal" A2input.txt
And it'd be nice if I could just alias it to something short and simple like "a", "b", "c", "d", etc...
However, some of those arguments have a quote, which is messing up the alias. Does anyone know how to actually escape the double quotes? I've tried things like '\"' and \" but nothing seems to work.
I'm using tcsh as my shell.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
以下所有内容在 tcsh 中工作以实现各种结果:
要查看 shell 如何解释这些结果,请运行不带参数的
alias
:括号中的任何内容都在子 shell 中运行。 如果您尝试设置环境变量,这会很糟糕,但除此之外大多无关紧要。
最后,这些示例的实际作用如下:
The following all work in
tcsh
to accomplish various results:To see how these are interpreted by the shell, run
alias
with no arguments:Anything in parentheses is run in a subshell. This would be bad if you're trying to set environment variables, but mostly irrelevant otherwise.
Finally, here's what the examples actually do:
我通过将带有双引号的字符串存储在变量中并用单引号括起来的字符串来使其工作。 当我使用变量时,我将其放在单引号内。
示例:
我在 OSX 上使用 tcsh 对此进行了测试
I got it to work by storing the string with the double quote in a variable with the string surrounded by single quotes. When I use the variable I up inside single quotes.
Example:
I tested this with tcsh on OSX
tcsh
有一个更新的变量backslash_quote
。 不确定何时添加,但6.18.01
(OS X El Capitan 上的版本)和6.19
(撰写本文时的最新稳定版本)支持它。 这使得可以转义引号内的'
、"
和`
。如果您不想使用此选项,您的选择仅限于在符号周围使用不同类型的引号
或根本不使用引号并随意反斜杠。
tcsh
has a newer variablebackslash_quote
. Not sure when it was added but it is supported in6.18.01
(version on OS X El Capitan) and6.19
(latest stable release at time of writing). This makes it possible to escape'
,"
, and`
inside of quotation marks.If you don't want to use this option, your choices are limited to using a different type of quote around the symbol
or not using quotes at all and liberally backslashing things.
看来
\"
和\'
不能按您预期工作的原因是csh
传统上不支持此类语法,所以,如果 tcsh 无条件支持它,那么这些旧的脚本可能不再正常工作,正如另一个答案中提到的,tcsh 本身有
set backslash_quote<。 /code>
功能;但是,与上述答案中暗示的不同,这并不是一个新功能,它只是 tcsh 特定的功能,并且实际上已添加到 tcsh 至少大约 27 年前 — 该功能首次记录在
tcsh.man,v 3.8 1991/07/25 04:50:55
,这几乎不合格作为“新”。 .1
It would appear that the reason that
\"
and\'
don't work as you expect is thatcsh
traditionally didn't support such syntax, so, iftcsh
were to unconditionally support it, then such older scripts may not work properly anymore.As mentioned in another answer, tcsh itself has the
set backslash_quote
feature; however, unlike implied in the mentioned answer, this is hardly a new feature, it's just a tcsh-specific one, and was actually added to tcsh at least some 27 years ago — the feature was first documented in the manual page attcsh.man,v 3.8 1991/07/25 04:50:55
, which hardly qualifies it as "new".http://mdoc.su/n,f,d/tcsh.1
如果您无法使用别名,只需编写一个简短的 shell 脚本 chmod +x,然后将其放在 $PATH 中的某个位置(例如 $HOME/bin):
我对 tcsh 没有任何经验,但是bash 你可以像以下任何一个那样做:
也许类似的东西可以在 tcsh 中工作?
If you can't get an alias to work, just write a short shell script, chmod +x, and put it somewhere in your $PATH (like $HOME/bin):
I don't have any experience with tcsh, but with bash you do it like any of these:
Maybe something similar will work in tcsh?
在双引号中转义双引号 - 将双引号括起来以用单引号括起来的双引号进行转义 - '"'"'"'
如果您能理解以下命令,那么您会得到它:
escape double quote in double quote - surround the double quote to escape with double quotes which are surrounded by single quote - '"'"'"'
if you can understand below commands, then you get it: