Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding functions in .cshrc in C-Shell

I want to add custom functions in my .cshrc file to execute some functionality with some inputs through my command line. I'm using C-shell. is there any way I could implement this or any work around to get the desired result?

like image 696
keerthan kumar Avatar asked Oct 19 '25 10:10

keerthan kumar


1 Answers

C Shell doesnt support functions.

I suggest you can create scripts to emulate the functions and then use alias in the .cshrc file to call those scripts when you type your command in the command line.

e.g , i want to define a new command called test in my csh environment. So i would add the below line in the .cshrc file

alias test "${HOME}/.test.sh"

Now i would create a .test.sh script in my ${HOME} directory ( or whereever you want it to be) and put the logic for the command inside the script.

An example as follows:

/home/abis> cat .test.sh 
#!/usr/bin/ksh

echo $1 $2

Then i would give execute permission to the .test.sh script and source the .cshrc file( it would be done anyway when you open a new login shell).

Then when i execute the command from the command line , the actual script would be called.

/home/abis> test "Hello" "World"
Hello World
like image 197
Abis Avatar answered Oct 22 '25 06:10

Abis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!