I want to write a shell script that can work with C-based [tcsh,csh etc] and non C-based [bash,ksh etc] shells. I need to declare some shell variables in this script and different shells has different syntax to declare shell variables. So, my problem is how to declare my variable in script so that it can run in all the shells?
my test.sh is as follows #!/bin/sh abc=7 myname=bhopal ...... ....
So, now the shell script can be invoked in following manners a) 1. chmod +x test.sh 2. ./test.sh
b) 2. /bin/tcsh test.sh
In case a) the "sh" shell will be used to execute test.sh and it will run successfully, but if the b) method is used to run the script it will fail.
One of the solution I can think of is to test the shell used to invoke the script e.g.
if [invoke_shell_name contains either tcsh or csh] then set abc=12 set myname=bhopal else abc=12 myname=bhopal fi ... ...
So, my quesiton is can I determine the shell script used to execute my shell script on the fly?
I will appreciate any other approach to write a SHELL independent script.