为什么 csh(tcsh) 别名在一行中定义和调用时不起作用?
Why do csh(tcsh) aliases not work when defined and invoked on one line?
[请不要推荐我不用csh。电气工程界与它有着千丝万缕的联系。谢谢!]
当我这样做时:
csh -f -c "alias foo bar; foo"
我得到:
foo: Command not found.
同样,当我这样做时:
#!/bin/csh -f
alias foo bar; foo
我也一样foo: Command not found.
。但是,这按预期工作:
#!/bin/csh -f
alias foo bar
foo
给出:
bar: Command not found.
这只是 csh/tcsh 中的一个错误吗?或者这是故意的?我必须处理别名,因为我使用的环境在很大程度上依赖于它们来配置工具集(包括模块)。但这基本上意味着我不能用 csh -f -c 调用短的 csh 脚本。我必须将命令转储到文件 chmod +x 并调用它。没什么大不了的。但我只是想知道是否有办法让这个 buggy/quirky shell 识别同一行上定义的别名。
这是记录在案的 csh 行为:别名替换发生在每个输入行被读取并拆分为命令之后,但在执行任何命令(包括您的 alias
命令)之前。
来自 csh(1)
手册:
Alias substitution
The shell maintains a list of aliases that can be established, displayed
and modified by the alias
and unalias
commands. After a command line is scanned, it is parsed into distinct commands and the first word of each
command, left-to-right, is checked to see if it has an alias. If it
does, then the text that is the alias for that command is reread with the
history mechanism available as though that command were the previous
input line. The resulting words replace the command and argument list.
If no reference is made to the history list, then the argument list is
left unchanged.
[请不要推荐我不用csh。电气工程界与它有着千丝万缕的联系。谢谢!]
当我这样做时:
csh -f -c "alias foo bar; foo"
我得到:
foo: Command not found.
同样,当我这样做时:
#!/bin/csh -f
alias foo bar; foo
我也一样foo: Command not found.
。但是,这按预期工作:
#!/bin/csh -f
alias foo bar
foo
给出:
bar: Command not found.
这只是 csh/tcsh 中的一个错误吗?或者这是故意的?我必须处理别名,因为我使用的环境在很大程度上依赖于它们来配置工具集(包括模块)。但这基本上意味着我不能用 csh -f -c 调用短的 csh 脚本。我必须将命令转储到文件 chmod +x 并调用它。没什么大不了的。但我只是想知道是否有办法让这个 buggy/quirky shell 识别同一行上定义的别名。
这是记录在案的 csh 行为:别名替换发生在每个输入行被读取并拆分为命令之后,但在执行任何命令(包括您的 alias
命令)之前。
来自 csh(1)
手册:
Alias substitution
The shell maintains a list of aliases that can be established, displayed and modified by the
alias
andunalias
commands. After a command line is scanned, it is parsed into distinct commands and the first word of each command, left-to-right, is checked to see if it has an alias. If it does, then the text that is the alias for that command is reread with the history mechanism available as though that command were the previous input line. The resulting words replace the command and argument list. If no reference is made to the history list, then the argument list is left unchanged.