C Shell登录脚本中的函数而不是别名 [英] Function instead of alias in C shell login script

查看:131
本文介绍了C Shell登录脚本中的函数而不是别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主题,如果您想使用参数,则可以在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆