题
我试图运行以下命令:
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"类,等等。
然而,其中一些论点有一个报价,这是搞乱了别名。任何人都不会知道如何实际上逃脱的双引号?我已经试过了事情就像'\"'and\"但似乎没有任何工作。
我使用的tcsh会因为我的外壳。
解决方案
我得到它通过存储与在与由单引号所包围的字符串的变量双引号字符串工作。当我使用可变我了单引号内。结果 例如:
[11:~] phi% [11:~] phi% set text = 'a quote "' [11:~] phi% alias ec echo '$text' [11:~] phi% ec a quote " [11:~] phi% [11:~] phi% alias ec echo this has '$text' [11:~] phi% ec this has a quote " [11:~] phi%
我的tcsh在OSX上测试此
其他提示
在tcsh
下面所有的工作以实现各种效果:
alias t echo hello world # you may not actually need any quotes alias u 'echo "hello world"' # nested quotes of different types alias v echo\ \"hello\ world\" # escape everything alias w echo '\;'hello'";"' world # quote/escape problem areas only alias x 'echo \"hello world\"' # single quote and escape for literal " alias y "echo "\""hello world"\" # unquote, escaped quote, quote ("\"") alias z 'echo '\''hello world'\' # same goes for single quotes ('\'')
要了解这些是由shell解释,不带参数运行alias
:
% alias t (echo hello world) u echo "hello world" v echo "hello world" w (echo \;hello";" world) x echo \"hello world\" y echo "hello world" z echo 'hello world'
在括号中任何一个子shell运行。如果你想设置环境变量这将是坏的,但大多是不相关的,否则。
最后,这里就是例子实际上做:
% t; u; v; w; x; y; z hello world hello world hello world ;hello; world "hello world" hello world hello world
tcsh
具有较新的变量backslash_quote
。不知道当它被添加,但它是在6.18.01
支持,(在写作时最新的稳定版)(上OS X埃尔卡皮坦版)6.19
。这使得有可能逃脱引号内'
,"
,和`
。
set backslash_quote
set sentence = 'I\'m a little teapot.'
set sentence2 = "The man said \"hello\""
如果您不想使用此选项,您的选择是有限的使用不同类型的报价符号周围
"The man said "'"'"hello"'"'
或不使用在所有的报价和宽松backslashing的东西。
The\ man\ said\ \"hello\"
如果你不能得到一个别名工作,只写一个短的shell脚本,使用chmod + x,并把它的地方在你的$ PATH(如$ HOME /箱):
#!/bin/tcsh
replace -x "must" ...
我没有与任何tcsh的经验,但在bash你做任何喜欢这些:
alias t='echo "hello world"' # using single quotes to enclose entire string
alias t=echo\ \"hello\ \ world\" # escape " and <space>
alias t="echo \"hello world\"" # double-quote + escape inner double quotes
也许类似的东西会在tcsh的工作?
它会出现的原因 \"
和 \'
不像你期望的是, csh
传统上并不支持这样的语法,因此,如果 tcsh
要无条件地支持它,那么这样的老剧本不可能正常工作了。
提到的另一个答案,tcsh会本身所具有的 set backslash_quote
特征;然而,不同的暗示,在所提到的答复,这绝不是一个新的功能,它只是一个tcsh会特有的一种,而实际上是加入 tcsh会 至少有一些27年前的功能是第一个有记录在手页 tcsh.man,v 3.8 1991/07/25 04:50:55
, ,这几乎不符合它作为"新的"。
backslash_quote (+) If set, backslashes (`\') always quote `\', `'', and `"'. This may make complex quoting tasks easier, but it can cause syntax errors in csh(1) scripts.