C Shell登录脚本中的函数而不是别名 [英] Function instead of alias in C shell login script
问题描述
我在此主题,如果您想使用参数,则可以在shell登录脚本中添加函数而不是别名.但是,我在带有别名的部分的.cshrc文件中放置了以下代码:
I saw in this topic that you can add a function in the shell login script instead of an alias if you want to use parameters. However, I placed the following code inside my .cshrc file in the section with aliasses:
function gf()
{
grep -n $1 `find .` | grep -v "can't open"
}
但是当我输入source .cshrc时,我得到了错误消息:错误地放置了(). C外壳程序的语法与Bash外壳程序的语法不同吗?如果是这样,正确的语法是什么?
But when I type source .cshrc, I get the error message: Badly placed ()'s. Is the syntax different for a C shell than in a Bash shell? If so, what is the correct syntax?
推荐答案
不幸的是,您无法像大多数其他shell一样在csh
中定义函数. csh
中不存在此功能.
Unfortunately, you can't define functions in csh
, like you can in most other shells. This feature does not exist in csh
.
唯一的选择是创建脚本并将其放置在PATH
上的目录中,例如~/bin
.
The only alternative is to create a script and place it in a directory on your PATH
e.g. ~/bin
.
这篇关于C Shell登录脚本中的函数而不是别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!