Function instead of alias in C shell login script

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

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.


If you are looking for passing only one argument, just put \!$ where you wish your argument to sit.

For example:

If you put alias mygrep grep -i \!$ myfile.txt in ~/.cshrc, and run mygrep mykeyword, csh will run alias mygrep grep -i mykeyword myfile.txt.

See this for more info.

Tags:

Shell

Alias

Login