为什么 Grave Keys 导致 CSH 将字符串解释为命令?
Why are Grave Keys Causing CSH to Interpret a String as a Command?
我有一个 csh 脚本 运行 一个 perl 脚本。命令是
`./test.pl`
这会引发错误读取
Hello: Command not found.
csh 脚本不包含 'Hello',但是 perl 脚本包含一行
print "Hello world!\n";
删除原始命令周围的坟墓键修复了错误。怎么回事?
因为这是他们应该做的。
来自我系统上的 man csh
(这是 tcsh
的文档):
Command substitution
Command substitution is indicated by a command enclosed in ``'. The output from such a
command is broken into separate words at blanks, tabs and newlines, and null words are
discarded. The output is variable and command substituted and put in place of the original string.
Command substitutions inside double quotes (`"') retain blanks and tabs; only newlines
force new words. The single final newline does not force a new word in any case. It is
thus possible for a command substitution to yield only part of a word, even if the command
outputs a complete line.
By default, the shell since version 6.12 replaces all newline and carriage return characters in the command by spaces. If this is switched off by unsetting csubstnonl, newlines
separate commands as usual.
如果您将 Hello World!
分配给环境变量 TEST
,则
echo $TEST
$TEST
与
相同
echo 'Hello' 'World!'
'Hello' 'World!' # Fails: No program named Hello
因为$TEST
被替换成其内容的拆分版本。这里也是一样。
echo `./test.pl`
`./test.pl`
与
相同
echo 'Hello' 'World!'
'Hello' 'World!' # Fails: No program named Hello
我有一个 csh 脚本 运行 一个 perl 脚本。命令是
`./test.pl`
这会引发错误读取
Hello: Command not found.
csh 脚本不包含 'Hello',但是 perl 脚本包含一行
print "Hello world!\n";
删除原始命令周围的坟墓键修复了错误。怎么回事?
因为这是他们应该做的。
来自我系统上的 man csh
(这是 tcsh
的文档):
Command substitution
Command substitution is indicated by a command enclosed in ``'. The output from such a command is broken into separate words at blanks, tabs and newlines, and null words are discarded. The output is variable and command substituted and put in place of the original string.
Command substitutions inside double quotes (`"') retain blanks and tabs; only newlines force new words. The single final newline does not force a new word in any case. It is thus possible for a command substitution to yield only part of a word, even if the command outputs a complete line.
By default, the shell since version 6.12 replaces all newline and carriage return characters in the command by spaces. If this is switched off by unsetting csubstnonl, newlines separate commands as usual.
如果您将 Hello World!
分配给环境变量 TEST
,则
echo $TEST
$TEST
与
相同echo 'Hello' 'World!'
'Hello' 'World!' # Fails: No program named Hello
因为$TEST
被替换成其内容的拆分版本。这里也是一样。
echo `./test.pl`
`./test.pl`
与
相同echo 'Hello' 'World!'
'Hello' 'World!' # Fails: No program named Hello