How do I know which unix shell I am using.

How do I know which unix shell I am using.

Post by Gir » Wed, 04 Feb 2004 04:53:52



I want to know how I can figure out which shell I am using. Can
someone tell me how I can get this info? Any command like uname -a to
know the system info.
 
 
 

How do I know which unix shell I am using.

Post by Chris F.A. Johnso » Wed, 04 Feb 2004 05:40:44



> I want to know how I can figure out which shell I am using. Can
> someone tell me how I can get this info? Any command like uname -a to
> know the system info.

    There have been many attempts to answer this, none has been
    totally successful.

    The best way is to test for the capabilities you want or need in
    your script.

    Some shells have a variable that gives you the information; bash
    has BASH_VERSION, pdksh has KSH_VERSION, ksh93 has a variable that
    uses an illegal name (${.sh.version}), so is useless in other
    shells; pdksh and ksh88 will print an error message and continue,
    but a Bourne shell or bash will exit.

    If you are more specific about what you need to do, I am sure
    someone will come up with a method to do what you need.

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

How do I know which unix shell I am using.

Post by Stephane CHAZELA » Wed, 04 Feb 2004 07:53:07


2004-02-2, 11:53(-08), Giri:

Quote:> I want to know how I can figure out which shell I am using. Can
> someone tell me how I can get this info? Any command like uname -a to
> know the system info.

For a more general approach to the problem, the following
script will try to tell which interpreter it is run by. Example
of result with different interpreters:

    akanga: akanga
       ash: ash/BSD sh
      bash: bash 2.05b.0(1)-release
     bash1: bash 1.14.7(1)
 bash-2.02: bash 2.02.1(1)-release
       bsh: Bourne-like shell
   cmd.exe: Windows_NT D:\WINDOWS\system32\cmd.exe
       csh: csh
 cygwin-sh: ash/BSD sh
        es: es version 0.9-beta1 12-August-1997
   es-0.67: es version 0.67: 30 Sep 1992
expect5.28: expect 5.28.1 (Tcl 8.0p2)
       ksh: ksh88
     ksh93: ksh93 Version M 1993-12-28 n+
      perl: perl 5.8.0

    python: python 2.0 (#2, Dec 17 2000, 18:49:55)
[GCC 2.95.2 19991024 (release)]

    rc-1.4: rc
      ruby: ruby 1.6.7
     tclsh: tcl 8.0p2
      tcsh: tcsh 6.12.00 (Astron) 2002-07-23 (i386-intel-linux) options 8b,nls,dl,al,rh,color,filec
      wish: wish (Tcl 8.0p2, Tk 8.0)
       zsh: zsh 4.1.1-dev-1
 zsh-3.0.7: zsh 3.0.7
 zsh-4.0.4: zsh 4.0.4
    Uv5 sh: possibly pre-Bourne UNIX V1-6 shell
    Uv6 sh: possibly pre-Bourne UNIX V1-6 shell
    Uv7 sh: Bourne-like shell without function


[exit[if {[lsearch -exact [package names] Expect]>=0} {puts expect\ [\
package require Expect]\ (Tcl\ [info patchlevel])} elseif {[lsearch -exact [\
package names] Tk]>=0} {puts wish\ (Tcl\ [info patchlevel],\ Tk\ [package \
require Tk])} else {puts tcl\ [info patchlevel]}]]' >/dev/null ' {\">/dev/null \
">"/dev/null" +"\'";q='''=.q,';q=%!\"

"';eval catch $2 ^'&version {eval ''echo <='^ $2 ^'&version''}';exit};e='"\
"';if (eval '{let ''a^~a''} >[2] /dev/null'){e='"\
"';exec echo akanga};eval exec echo rc $2 ^ version;\" > /dev/null
: #;echo possibly pre-Bourne UNIX V1-6 shell;exit
if { bindkey >& /dev/null } then
exec echo $version
else
exec echo csh
endif

cls
echo %OS% %COMSPEC%
goto fin
", unless eval 'printf "perl %vd\n",$^V;exit;'> "/dev/null";eval ': "\'';
=S"';f=false e=exec\ echo n=/dev/null v=SH_VERSION;`(eval "f() { echo :

Quote:};f")2>$n` $f||$e Bourne-like shell without function

case `(: ${_z_?1}) 2>&1` in 1) $e ash/BSD sh;;esac;t(){
eval "\${$1$v+:} $f &&exec echo ${2}sh \$$1$v";};t BA ba;t Z z;t K pdk
a=:\ $f;case `(typeset -Z2 b=0;$e $b)2>$n` in 00) (`eval '$e ${a:1}'`:)2>$n \
||eval '$e ksh93 ${.sh.version}';$e ksh88;;esac;case `(eval '$e ${a#*s}$($e 1
)$((1+1))')2>$n` in e12)$e POSIX shell;;esac;$e Bourne-like shell;: !
print "ruby ",VERSION,"\n";exit;' '''
import sys;print "python",sys.version;z='\
: fin } '

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]

 
 
 

How do I know which unix shell I am using.

Post by Ra » Wed, 04 Feb 2004 22:32:10


echo $SHELL

> 2004-02-2, 11:53(-08), Giri:
> > I want to know how I can figure out which shell I am using. Can
> > someone tell me how I can get this info? Any command like uname -a to
> > know the system info.

> For a more general approach to the problem, the following
> script will try to tell which interpreter it is run by. Example
> of result with different interpreters:

>     akanga: akanga
>        ash: ash/BSD sh
>       bash: bash 2.05b.0(1)-release
>      bash1: bash 1.14.7(1)
>  bash-2.02: bash 2.02.1(1)-release
>        bsh: Bourne-like shell
>    cmd.exe: Windows_NT D:\WINDOWS\system32\cmd.exe
>        csh: csh
>  cygwin-sh: ash/BSD sh
>         es: es version 0.9-beta1 12-August-1997
>    es-0.67: es version 0.67: 30 Sep 1992
> expect5.28: expect 5.28.1 (Tcl 8.0p2)
>        ksh: ksh88
>      ksh93: ksh93 Version M 1993-12-28 n+
>       perl: perl 5.8.0

>     python: python 2.0 (#2, Dec 17 2000, 18:49:55)
> [GCC 2.95.2 19991024 (release)]

>     rc-1.4: rc
>       ruby: ruby 1.6.7
>      tclsh: tcl 8.0p2
>       tcsh: tcsh 6.12.00 (Astron) 2002-07-23 (i386-intel-linux) options 8b,nls,dl,al,rh,color,filec
>       wish: wish (Tcl 8.0p2, Tk 8.0)
>        zsh: zsh 4.1.1-dev-1
>  zsh-3.0.7: zsh 3.0.7
>  zsh-4.0.4: zsh 4.0.4
>     Uv5 sh: possibly pre-Bourne UNIX V1-6 shell
>     Uv6 sh: possibly pre-Bourne UNIX V1-6 shell
>     Uv7 sh: Bourne-like shell without function

> 'echo' +"'\

> [exit[if {[lsearch -exact [package names] Expect]>=0} {puts expect\ [\
> package require Expect]\ (Tcl\ [info patchlevel])} elseif {[lsearch -exact [\
> package names] Tk]>=0} {puts wish\ (Tcl\ [info patchlevel],\ Tk\ [package \
> require Tk])} else {puts tcl\ [info patchlevel]}]]' >/dev/null ' {\">/dev/null \
> ">"/dev/null" +"\'";q='''=.q,';q=%!\"

> "';eval catch $2 ^'&version {eval ''echo <='^ $2 ^'&version''}';exit};e='"\
> "';if (eval '{let ''a^~a''} >[2] /dev/null'){e='"\
> "';exec echo akanga};eval exec echo rc $2 ^ version;\" > /dev/null
> : #;echo possibly pre-Bourne UNIX V1-6 shell;exit
> if { bindkey >& /dev/null } then
> exec echo $version
> else
> exec echo csh
> endif
> : dos

> cls
> echo %OS% %COMSPEC%
> goto fin
> ", unless eval 'printf "perl %vd\n",$^V;exit;'> "/dev/null";eval ': "\'';
> =S"';f=false e=exec\ echo n=/dev/null v=SH_VERSION;`(eval "f() { echo :
> };f")2>$n` $f||$e Bourne-like shell without function
> case `(: ${_z_?1}) 2>&1` in 1) $e ash/BSD sh;;esac;t(){
> eval "\${$1$v+:} $f &&exec echo ${2}sh \$$1$v";};t BA ba;t Z z;t K pdk
> a=:\ $f;case `(typeset -Z2 b=0;$e $b)2>$n` in 00) (`eval '$e ${a:1}'`:)2>$n \
> ||eval '$e ksh93 ${.sh.version}';$e ksh88;;esac;case `(eval '$e ${a#*s}$($e 1
> )$((1+1))')2>$n` in e12)$e POSIX shell;;esac;$e Bourne-like shell;: !
> print "ruby ",VERSION,"\n";exit;' '''
> import sys;print "python",sys.version;z='\
> : fin } '

 
 
 

How do I know which unix shell I am using.

Post by Stephane CHAZELA » Wed, 04 Feb 2004 23:00:26


2004-02-3, 05:32(-08), Raj:

Quote:> echo $SHELL

~$ bash -c 'echo $SHELL'
/bin/zsh

The SHELL variable is set by no shell I know, it's just used
by applications such as vi, ftp, xterm so that they know which
shell to run when requested. It's generally set by "login" based
on your passwd entry, but can be modified at your will.

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]

 
 
 

How do I know which unix shell I am using.

Post by Chris F.A. Johnso » Thu, 05 Feb 2004 07:57:15



> 2004-02-2, 11:53(-08), Giri:
>> I want to know how I can figure out which shell I am using. Can
>> someone tell me how I can get this info? Any command like uname -a to
>> know the system info.

> For a more general approach to the problem, the following
> script will try to tell which interpreter it is run by. Example
> of result with different interpreters:



    I can't use it to test pdksh:

$ cat xx.sh
#!/usr/bin/pdksh
whichsh  ## contains the script below
## EOF
$ xx.sh
bash 2.05b.0(2)-release

    And it cannot be included in the script being tested, as it exits,
    and will not execute any subsequent commands.

    It cannot be sourced, as it will exit the calling shell.

> 'echo' +"'\

> [exit[if {[lsearch -exact [package names] Expect]>=0} {puts expect\ [\
> package require Expect]\ (Tcl\ [info patchlevel])} elseif {[lsearch -exact [\
> package names] Tk]>=0} {puts wish\ (Tcl\ [info patchlevel],\ Tk\ [package \
> require Tk])} else {puts tcl\ [info patchlevel]}]]' >/dev/null ' {\">/dev/null \
> ">"/dev/null" +"\'";q='''=.q,';q=%!\"

> "';eval catch $2 ^'&version {eval ''echo <='^ $2 ^'&version''}';exit};e='"\
> "';if (eval '{let ''a^~a''} >[2] /dev/null'){e='"\
> "';exec echo akanga};eval exec echo rc $2 ^ version;\" > /dev/null
>: #;echo possibly pre-Bourne UNIX V1-6 shell;exit
> if { bindkey >& /dev/null } then
> exec echo $version
> else
> exec echo csh
> endif
>: dos

> cls
> echo %OS% %COMSPEC%
> goto fin
> ", unless eval 'printf "perl %vd\n",$^V;exit;'> "/dev/null";eval ': "\'';
>=S"';f=false e=exec\ echo n=/dev/null v=SH_VERSION;`(eval "f() { echo :
> };f")2>$n` $f||$e Bourne-like shell without function
> case `(: ${_z_?1}) 2>&1` in 1) $e ash/BSD sh;;esac;t(){
> eval "\${$1$v+:} $f &&exec echo ${2}sh \$$1$v";};t BA ba;t Z z;t K pdk
> a=:\ $f;case `(typeset -Z2 b=0;$e $b)2>$n` in 00) (`eval '$e ${a:1}'`:)2>$n \
>||eval '$e ksh93 ${.sh.version}';$e ksh88;;esac;case `(eval '$e ${a#*s}$($e 1
> )$((1+1))')2>$n` in e12)$e POSIX shell;;esac;$e Bourne-like shell;: !
> print "ruby ",VERSION,"\n";exit;' '''
> import sys;print "python",sys.version;z='\
>: fin } '

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
 
 
 

How do I know which unix shell I am using.

Post by Stephane CHAZELA » Thu, 05 Feb 2004 08:26:45


2004-02-3, 22:57(+00), Chris F.A. Johnson:
[...]

Quote:>     I can't use it to test pdksh:

> $ cat xx.sh
> #!/usr/bin/pdksh
> whichsh  ## contains the script below

As it is, it is to be tested as:

interpreter whichsh

or

interpreter < whichsh

Or copy-paste it within the interpreter (yes, it will exit it,
for most interpreters).

It's not really intented to be useful actually. That was just
much fun to have a script that can be interpreted by such a wide
range of different interpreters with totally different syntaxes.
It can be /easily/ modified so that it does other things
whatever the interpreter (that's the only /useful/ usage of it I
can think of).

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]

 
 
 

How do I know which unix shell I am using.

Post by Carlos J. G. Duart » Thu, 05 Feb 2004 09:05:28



> For a more general approach to the problem, the following
> script will try to tell which interpreter it is run by. Example
> of result with different interpreters:

Awesome stuff! Did you wrote this? This should be one of the best "many
languages single source" program I've seen.

--
carlos ** http://cgd.sdf-eu.org

 
 
 

How do I know which unix shell I am using.

Post by Carlos J. G. Duart » Thu, 05 Feb 2004 09:07:11



> I want to know how I can figure out which shell I am using. Can
> someone tell me how I can get this info? Any command like uname -a to
> know the system info.

Well, for most unixes shell the following might do the trick:
ps | grep $$ | awk '{print $NF}'

--
carlos ** http://cgd.sdf-eu.org

 
 
 

How do I know which unix shell I am using.

Post by Chris F.A. Johnso » Thu, 05 Feb 2004 10:51:22




>> I want to know how I can figure out which shell I am using. Can
>> someone tell me how I can get this info? Any command like uname -a to
>> know the system info.

> Well, for most unixes shell the following might do the trick:
> ps | grep $$ | awk '{print $NF}'

    And if it returns "sh"?  That can be any one of several different
    shells. On *BSD it's ash, on Linux it's usually bash, on others
    it's a Bourne shell, etc..

    If it returns "bash" or "ksh", which version is it?

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

How do I know which unix shell I am using.

Post by Carlos J. G. Duart » Thu, 05 Feb 2004 11:34:48



>     And if it returns "sh"?  That can be any one of several different
>     shells. On *BSD it's ash, on Linux it's usually bash, on others
>     it's a Bourne shell, etc..

>     If it returns "bash" or "ksh", which version is it?

Give it a break, will you? Probably the guy just wants to know which
/bin/something he's running...

--
carlos ** http://cgd.sdf-eu.org

 
 
 

How do I know which unix shell I am using.

Post by Stephane CHAZELA » Thu, 05 Feb 2004 18:18:04


2004-02-04, 00:07(+00), Carlos J. G. Duarte:
[...]

Quote:> Well, for most unixes shell the following might do the trick:
> ps | grep $$ | awk '{print $NF}'

ps -o comm= -p "$$"
or
ps -o args= -p "$$"

with POSIX compliant ps.

Note that awk being a superset of grep, you generally don't need
to pipe them together. Grepping for "$$", you may retrieve every
line that contain $$, not only those for which the pid is $$.

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]

 
 
 

How do I know which unix shell I am using.

Post by Stephane CHAZELA » Thu, 05 Feb 2004 18:28:24


2004-02-04, 00:05(+00), Carlos J. G. Duarte:


>> For a more general approach to the problem, the following
>> script will try to tell which interpreter it is run by. Example
>> of result with different interpreters:

> Awesome stuff! Did you wrote this?

Yes, one year ago. I added languages one after the other,
starting with bourne-like/csh/Thomson/rc shells, adding tcl
ones (tclsh, wish, expect), ruby and COMMAND.COM in the end. I
couldn't manage to have it working with awk. I didn't even try
with scsh, ch or esh, but it becomes very tricky to add stuff,
as for each byte you add, you have to make sure it doesn't break
either interpreter.

Quote:> This should be one of the best "many
> languages single source" program I've seen.

Thank you. I have to admit I'm quite proud of that otherwise
useless script ;).

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]

 
 
 

How do I know which unix shell I am using.

Post by Heiner Steve » Sat, 28 Feb 2004 07:44:58



> I want to know how I can figure out which shell I am using. Can
> someone tell me how I can get this info? Any command like uname -a to
> know the system info.

The following script does not know as many different shell
dialects as Stephane's, but it's nevertheless useful:

     http://www.shelldorado.com/scripts/cmds/shtype

Example:

     $ shtype

Heiner
--
  ___ _

\__ \  _/ -_) V / -_) ' \    Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.shelldorado.com/

 
 
 

1. to know DOS is to know Unix?

I just met a couple people at some dinner and one guy says that if you
know DOS, you know Unix because many of the commands are similar.  I
didn't want to be rude, so I sat there mildly amused, (half-baked, of
course :).

So anyway, I figured these are just another couple of lusers.  Ever
tried to awk anything in DOS?  My find command doesn't work right
either, no grep, no su, no xargs, what the hell?  Do I have a faulty
version of DOS or something?

I suppose if all you want to do is mkdir, rmdir and cd and maybe ping
something, you're okay, but I really can't think of much more you could
do.

Just thought I'd share that - hope y'all don't mind.  The level of
luserness is reaching too high a state for me to contain myself for much
longer.

Whew - I just found a really great Unix command that works at the DOS
prompt.  exit.  That's much better.

2. FIXMAP-related change to mm/memory.c

3. How to know what shell I am ruuning from a C program?

4. Linux installation on IBM Thinkpad 380

5. How do I know which window manager I am using?

6. TOKEN RING? (unfortunately *IBM* Token Ring)

7. How do I know what system I am using?

8. long filenames

9. How do I know which window manager I am using?

10. I am a Linux Know Nothing, would like to know

11. What am I doing wrong here (UNIX-domain sockets don't work)?

12. Q what shell am I using?

13. Which shell am I using?