Current Shell

Current Shell

Post by Phill Wei » Sat, 18 Dec 1999 04:00:00



If I am running in csh and do a echo $SHELL it returns /bin/csh. If I then go
into ksh by typing ksh and gettting the $ prompt and type echo $SHELL,
it stiil returns /bin/csh. Is there a way to determine the current shell
one is running in?

Thanks in advance.

 
 
 

Current Shell

Post by Jehs » Sat, 18 Dec 1999 04:00:00



> Is there a way to determine the current shell one is running in?

Hm... This is cool: type "echo $0" and you'll see the command used to
invoke your current shell :)

--

ICQ 1900670 - 350467 GT Station - 6-0985 - HEF 214

 
 
 

Current Shell

Post by Jehs » Sat, 18 Dec 1999 04:00:00



> Hm... This is cool: type "echo $0" and you'll see the command used to
> invoke your current shell :)

Additionally, if you want the full path outputted (is that a word?),
type:
which `echo $0`

That is all.

Moshe

--

ICQ 1900670 - 350467 GT Station - 6-0985 - HEF 214

 
 
 

Current Shell

Post by Ajay Mata » Sat, 18 Dec 1999 04:00:00


All real shells store their name in the variable 0 (zero).

So, do an
        echo $0

I have seen some csh on which this does not work. That's why I said all
real shells :)

HTH

-ajay


> If I am running in csh and do a echo $SHELL it returns /bin/csh. If I then go
> into ksh by typing ksh and gettting the $ prompt and type echo $SHELL,
> it stiil returns /bin/csh. Is there a way to determine the current shell
> one is running in?

> Thanks in advance.

 
 
 

Current Shell

Post by Phill Wei » Sat, 18 Dec 1999 04:00:00



> All real shells store their name in the variable 0 (zero).

> So, do an
>    echo $0

> I have seen some csh on which this does not work. That's why I said all
> real shells :)

> HTH

> -ajay


> > If I am running in csh and do a echo $SHELL it returns /bin/csh. If I then go
> > into ksh by typing ksh and gettting the $ prompt and type echo $SHELL,
> > it stiil returns /bin/csh. Is there a way to determine the current shell
> > one is running in?

> > Thanks in advance.

On my system, $0 is used to store the previous command that was called. So,
if I`m in csh and type ksh, echo $0 will return ksh (the last command) I typed
to get to ksh. Similarly, if I execute the follwing shell script:

#!/bin/ksh
echo $0

and invoke it by saying x.sh, it returns "x.sh" from the echo. So, it seems I
am still in need of a way to determine the current shell name.

 
 
 

Current Shell

Post by Heiner Steve » Wed, 22 Dec 1999 04:00:00



> If I am running in csh and do a echo $SHELL it returns /bin/csh. If I then go
> into ksh by typing ksh and gettting the $ prompt and type echo $SHELL,
> it stiil returns /bin/csh. Is there a way to determine the current shell
> one is running in?

Try the following script "shtype":

Quote:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>(CUT)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

# shtype - determine shell type (hs '96)

#
# Knows sh, ksh, ksh93, csh, tcsh, bash, zsh
#
# Thanks to

#

# Check for Bourne shell or C shell dialect
set x = 1
test "$x" = 1 && goto CSH

# Bourne shell dialect

# Don't use external commands
PATH=   export PATH

# The standard Bourne shell does not know how to remove parts
# of a variable with ${VAR%%pattern}.
x="A.B"
x=`(echo ${x%%.*}) 2>/dev/null`
if [ "$x" = A ]
then
    # bash/zsh or ksh?
    # bash/zsh use $[...] for arithmetic evaluation.
    x=`(echo $[0+1]) 2>/dev/null`
    if [ "$x" = 1 ]
    then
        # zsh tests with ${+x} if variable x is set
        x=0
        x=`(echo ${+x}) 2>/dev/null`
        if [ "$x" = 1 ]
        then
            echo ZSH
        else
            echo BASH
        fi
    else
        # ksh or ksh93?
        # ksh93 can extract substrings from a variable.
        x=AB
        x=`(echo ${x:1:1}) 2>/dev/null`
        if [ "$x" = B ]
        then
            echo KSH93
        else
            echo KSH
        fi
    fi
else
    echo BSH
fi
exit 0

CSH:
# C-Shell dialect

# tcsh has a bindkey command
if { bindkey >& /dev/null } then
    echo TCSH
else
    echo CSH
endif
exit 0
<<<<<<<<<<<<<<<(CUT)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Please not that the first line of the script should be an empty line.

Heiner
--
 ___ _                          

\__ \  _/ -_) V / -_) ' \    UNIX Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.oase-shareware.org/shell/