Current Issue


Table of contents

CD-ROM

Sys Admin and The Perl Journal CD-ROM version 12.0

Version 12.0 delivers every issue of Sys Admin from 1992 through 2006 and every
issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!

Sys Admin Magazine > Archives > 2006 > December
SysAdminMag.com

Korn Shell Nuances

Ed Schaefer and John Spurgeon

We use the Korn shell almost exclusively. This month we'll investigate an eclectic mix of topics pertaining to the Korn shell and related shells:

  • How can you tell which shell you are using?
  • What happens if the shell isn't specified on the first line of a script?
  • Setting the environment variable PS1.
Which Shell Am I Using?

From the command line, how can users determine which shell they are currently using? Looking at the user's entry in the /etc/passwd file only indicates the user's login shell, not necessarily what the shell is now.

Similarly, the environment variable SHELL or shell may be set but not reset for any spawned child shells. The Solaris 9 man page for ksh states that SHELL is not set at all by the shell, but is set by login on some systems.

Within a script, $0 is set to the name of the script. But at the command line, $0 provides the name of the shell. For example, if you are using the Korn shell, then the command "echo $0" displays "-ksh".

This method also works for the Bourne shell. Spawn a Bourne shell and verify the child "sh" displays:

echo $0 
sh 
            
Unfortunately, this technique doesn't work with the shells csh and tcsh.

Probably the best method of tracing which shells are running is to use the ps command. One technique is to execute ps with no arguments. Echoing $$ obtains the process id of your current shell.




MarketPlace

�Six Sigma� Certified?
100% Online-Six Sigma Certificate From Villanova -Find Out More Now.

Project Management-Online
Nation's Leading Online PMP Course From Villanova-Find Out More Now.

Flowcharts from C/C++ code -- Free trial download
Understand C/C++ code in less time. A new team member ? Inherited legacy code ? Get up to speed faster with Crystal Flow for C/C++. Code-formatting improves readability. Flowcharts are integrated with code browser. Export flowcharts to Visio.

Automate Software Builds with Visual Build Pro
Easily create an automated, repeatable process for building and deploying software.

Wanna see your ad here?