Declaring shell variables!!
"Bhopal Singh" <bsingh-dv/[email protected]> Wed, 28 Sep 2005 21:24:09 +0530
| Newsgroups | gmane.user-groups.linux.delhi.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi All, 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=3D7 myname=3Dbhopal ...... .... So, now the shell script can be invoked in following manners a) 1. chmod +x test.sh = 2. ./test.sh or = 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=3D12 set myname=3Dbhopal else abc=3D12 myname=3Dbhopal 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. Thanks and Regards, ~Bhopal Success is not doing extraordinary things but doing ordinary things extraordinarily well!