I want to know that is any other way to get current shell name ?
Currently I am using $0 as we know that first argument or interpreter
name, but is this one is correct way to get shell name ???
Please provide me document links for this, if any.... Thanks in
advance.... :-)
> Hi, I m newbie to shell scripting.
> Use of $SHELL variable to get name current shell, but when I change my
> shell from login shell this variable is remain same ???
I think you are confusing the purpose of these things. The login
shell is what to run when a user logs in (and it may not even be a
command interpreter). The value in SHELL is the user's preferred
shell -- the one to use if there is a choice.
These are clearly linked, but they most definitely are not inevitably
the same. For example, bash will set SHELL to the full pathname of
the login shell but not if it is already set.
> I want to know that is any other way to get current shell name ?
> Currently I am using $0 as we know that first argument or interpreter
> name, but is this one is correct way to get shell name ???
It is a reasonable hint, but not much more. I think the question can
only be answered if you can say why you want to know. How will you
use the answer?
--
Ben.
Hi, thanks for reply. purpose is that we have most of the scripts
written in KSH but some of them are in TCSH, so while updating I want
to print current shell name.
So let say parent shell is bash and after that I run two script one in
KSH and TCSH, I wrote 'echo $SHELL' so that they will return me that
shell name.
But in both script returns me same result '/bin/bash', so this is what
I was not expecting.
So I want to know the scrip code that prints the current shell name,
like if I run KSH script then it results ksh or absolute path of that
and same thing for the TCSH script.
> ........
>> > I want to know that is any other way to get current shell name ?
>> > Currently I am using $0 as we know that first argument or interpreter
>> > name, but is this one is correct way to get shell name ???
>>
>> It is a reasonable hint, but not much more. I think the question can
>> only be answered if you can say why you want to know. How will you
>> use the answer?
>>
>> --
>> Ben.
It's best to snip sigs -- even short ones.
> Hi, thanks for reply. purpose is that we have most of the scripts
> written in KSH but some of them are in TCSH, so while updating I want
> to print current shell name.
>
> So let say parent shell is bash and after that I run two script one in
> KSH and TCSH, I wrote 'echo $SHELL' so that they will return me that
> shell name.
As you've found, SHELL won't work at all and $0 does not do it either.
If it is just two shells, then I'd pick something likely to be unique
about then. For example, csh defines $shell (note case) and ksh does
not. ksh defines KSH_VERSION and csh does not. Of course, none of
these protect you against a deliberately written 'bad' script.
tcsh and ksh are so different that you won't be able to do much in the
common syntax.
<snip>
--
Ben.
> I want to know that is any other way to get current shell name ?
> Currently I am using $0 as we know that first argument or interpreter
> name, but is this one is correct way to get shell name ???
On Linux you can use 'readlink /proc/$$/exe'. I don't know if it works
on other Unixes...
--
Vítor De Araújo
Hi.
I've found that command "ps -p $$" will produce output amenable to
additional processing on Linux, Solaris, and FreeBSD ... cheers, makyo
Also:
set argv = x
test $1 = x && goto csh
echo sh
exit
csh:
echo csh
See also http://stchaz.free.fr/which_interpreter for ideas on
how to support more different interpreters.
--
Stᅵphane
Thank u all of you for the reply... :-)
all of them are unique so it helps me and clear other fundamental of
unix....
Thanks again... :-)