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.
|