Re: Declaring shell variables!!

Subhasis Ray <[email protected]> Thu, 29 Sep 2005 11:31:49 +0530
Newsgroups gmane.user-groups.linux.delhi.devel
Message-ID <[email protected]>
Hi,

Method a) is the best way to run..... you need not worry on the shell being
used. Trying to make the script compatible with all available shells would
unnecessarily complicate matters, unless there is a specific requirement and
you have no other choice.

Cheers

Subhasis

On 9/28/05, Bhopal Singh <bsingh-dv/[email protected]> wrote:
>
> 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!
>
> _______________________________________________
> The ILUGD-Dev mailing list
> Ilugd-dev-cunTk1MwBs8/[email protected]
>
> Subscribe/Unsubscribe/Suspend your list membership at:
> http://frodo.hserus.net/mailman/listinfo/ilugd-dev
>