Function instead of alias in C shell login script

我与影子孤独终老i 提交于 2019-12-18 04:38:05

问题


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"
}

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?


回答1:


Unfortunately, you can't define functions in csh, like you can in most other shells. This feature does not exist in csh.

The only alternative is to create a script and place it in a directory on your PATH e.g. ~/bin.




回答2:


Here is my solution:

#!/bin/csh

if ("$1" == "run") goto $2

echo "Now in default mode"

echo "Calling myself"

csh -f dummy run sub1

csh -f dummy run sub2

exit


sub1:

echo "In sub1"

exit

sub2:

echo "In sub2"

exit


来源:https://stackoverflow.com/questions/13916515/function-instead-of-alias-in-c-shell-login-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!