I'm trying to declare a function in tcsh and to call it.
#! /bin/tcsh -f
helloWorld () {
echo "a"
}
helloWorld
I'm getting the following error:
< 512 mews2895 ~/tmp/script> 1.sh
Badly placed ()'s.
Does anyone here what the problem might be?
Thanks
tcsh does not support functions.
Best solution: Use a shell that does, such as bash.
If you must use tcsh for some reason, aliases will solve your immediate problem, but are much weaker than functions.
alias helloWorld 'echo "a"'
Another possible solution is to invoke a separate script. (You'll have to ensure that the invoked script is in your $PATH
.)
There are not functions in tcsh. So I see 2 options:
Use aliases: https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.2.0/com.ibm.zos.v2r2.bpxa500/alias.htm
Use goto. (People tend to criticize go-to, but It actually depends on the context).
There is an other option, use source if you want to organize your code with multiple files:
To run a shell script in your current environment, without creating a new process, use the source command. You could run the calculate shell script this way: source calculate Should you want to use a shell script that updates a variable in the current environment, run it with the source command.
src: OS/390 UNIX System Services tcsh (C Shell) Kit Support Guide - IBM
I think that 'use a different shell' should not be a valid response.
Regards, Pablo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With