previous
section   next section   upper level

Section 12: Customizing the UNIX Shell

The UNIX shell is a actually a user program that the kernel runs for you when you log in. There is usually more than one shell available on most UNIX systems. The most common shells available on UNIX systems are the Bourne Shell (sh), the C Shell (csh) and the Korn shell (ksh). Here is a summary of features available on these three shells, adapted from the Hewlett Packard "Beginner's Guide to HPUX."

Feature Function sh csh ksh
Job control Allows processes to be
run in the background
No Yes Yes
History substitution Allows previous commands to be
saved, edited, and reused
No Yes Yes
File name completion Allows automatic completion of
partially typed file name
No Yes Yes
Command line editing Allows the use of an editor to
modify the command line text
No No Yes
Command aliasing Allows the user to rename
commands
No Yes Yes

Choosing your shell

It is possible to invoke any available shell from within another shell. To start a new shell, you can simply type the name of the shell you want to run, ksh, csh, or sh.

It is also possible to set the default startup shell for all your future sessions. The default shell for your account is stored in the system database /etc/passwd, along with the other information about your account. To change your default shell, use the chsh command The cshs command requires one argument, the name of the shell you want as your default. To change tour default shell to the C shell, you could enter the command

chsh /bin/csh
On ISU's HP-UX system, the available shells are /bin/sh, /bin/posix/sh, and /bin/csh. The default shell for accounts is /bin/posix/sh, which is, for all practical purposes, the same as ksh.

Default file access permissions

Whenever you create a file or directory in a UNIX filesystem, the newly created file or directory is stamped with a default set of permissions. That default set of permissions is stored in a variable called the umask. You can change the value of umask to suit your preferences. To see the current value of the umask variable, enter the shell command:
umask

The umask is stored as an octal (base 8) number, that defines which permissions to deny. As you recall, three kinds of file permissions (read, write, and execute) are given for each of three classes of users (owner, group, and others). Each of the nine permissions is specified as a zero (allow access), or a one (deny access).

To set your umask to deny write permission to group and others, use the command

umask 022
To deny all access to group and others, use the command
umask 077

Some versions of UNIX provide a more user-friendly way of specifying your umask. In HP-UX sh-posix (or ksh), you are allowed to specify the access permissions in manner of the chmod command. The command

umask u=rwx,g=r,o=r
would set the umask to deny write and execute permissions to the group, and to others. That kind of command syntax will not work in HP-UX's C shell or Bourne shell. The HP-UX posix shell also allows the use of the command
umask -S
to print your umask setting in a more readable fashion.

Customizing with user login scripts

The remainder of this section describes some of the ways you can initialize ksh, by presenting the default user login scripts provided to users of ISU's CWIS machine. The scripts have been annotated with descriptions of the purpose of each set of commands.

The .profile file

#!/bin/posix/sh

#******************************************************************************
# Run the script .shrc in every subshell.
#******************************************************************************
ENV="$HOME/.shrc";export ENV

#******************************************************************************
# Leave a sign of last login in user's home directory
# Remove this line if you don't want such records left.
# All logins are logged elsewhere, anyway.
#******************************************************************************
touch $HOME/.lastlogin
chmod 600 $HOME/.lastlogin

#******************************************************************************
# THREE TYPES OF TERMINAL-CHOOSING MECHANISMS ARE PRESENTED BELOW. ONLY
# ONE SHOULD BE USED. AUTOMATIC DETECTION OF TERMINAL TYPE IS THE DEFAULT.
#******************************************************************************

#******************************************************************************
# Uncomment the following line (i.e. remove # at the beginning of line)
# to make it so you're prompted for terminal type at login (rather than 
# having term type hard-coded or having the system automatically detect
# your terminal type). Replace 'vt220' with another term type if you want a 
# different default terminal type presented with the user prompt.
#******************************************************************************
# eval ` tset -s -Q -m ":?vt220" `

#******************************************************************************
# Uncomment the following line (i.e. remove # at beginning of line)
# if you want to hard-code a terminal type. 
# Replace 'vt220' with any desired terminal type. Use this option only if
# you are always using the same type of terminal, and if the system doesn't
# seem to properly detect your terminal type.
#******************************************************************************
# TERM=vt220

#******************************************************************************
# If you chose either of the above terminal-choosing options, comment out
# the following section from 'if' to 'fi' (insert a # at the beginning of
# each line). Otherwise, the default terminal handling for terminal access
# is to have the system attempt to detect your terminal type.
#******************************************************************************
if [ "${TERM}X" = "X" ]
then 
  TERM=`ttytype`
  case $TERM in
    *2382* | *2392* | *2393* | *2394* |  *2397* | *2621*  )  TERM="hp" ;; 
    *2621* | *2622* | *2623* | *2624* |  *2625* | *2626*  )  TERM="hp" ;;
    *2627* | *2628* | *2640* | *2641* |  *2644* | *2645*  )  TERM="hp" ;;
    *2647* | *2648* | *2649* | *150*  | *70092* | *70094* )  TERM="hp" ;;
  esac
fi

#*****************************************************************************
# Leave this line alone: it applies for all terminal-setting options
#*****************************************************************************
export TERM

#******************************************************************************
# Set up the terminal:
#******************************************************************************
stty hupcl ixon ixoff ienqak -parity
stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z"
tabs

#*****************************************************************************
# Display little menu of options
#*****************************************************************************
/usr/local/bin/menu


The .shrc file


#!/bin/posix/sh

#*****************************************************************************
# Set default permissions so that you can read and write all files, and that
# others can't. Changing this can potentially mess up the security of your 
# account, so make sure you know what you're doing before changing this.
#*****************************************************************************
umask 077 

#******************************************************************************
# set paths: PATH tells the shell where to look for programs/commands when
# you type command or program names. MANPATH tells the shell where to look
# for unix 'man' pages. NNTPSERVER tells newsreaders to get usenet news from
# the cwis computer.
#******************************************************************************
PATH=$HOME/bin:.:/bin/posix:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:/usr/bin/X11:/usr/local/bin/X11:/usr/contrib/bin/X11:/share/gen/bin:/share/X11/bin

MANPATH=/usr/man:/usr/local/man:/usr/contrib/man:/share/gen/man:/share/X11/man

NNTPSERVER=localhost

#******************************************************************************
# Set up the shell environment variables: 
# HOST and GROUPNAME get set for old cwis menus.
# If you want an editor other than pico (like vi or emacs) to be your default 
#     editor, replace pico with the name of your preferred editor.
# HISTSIZE determines how many of your previous commands are retained for 
#     recalling. 
# The line with PAGER determines the default pager to use for reading through
#     documents one page at a time. 
# The line with LESS makes it so informative keystroke prompts are put at the
#     bottom of the screen when using the less pager.
# LPDES determines which printer queue your print jobs submitted with the lp 
#     command go to. This line is changed by the 'printers' program, so try 
#     not to radically alter this line. You can manually change the queue name
#     here if you want to.
#******************************************************************************
export HOST=`hostname`
export GROUPNAME=`groups -p $LOGNAME`
EDITOR=pico;export EDITOR
HISTSIZE=200;export HISTSIZE
PAGER="less";export PAGER
LESS='-c -P spacebar\:page ahead b\:page back /\:search ahead \?\:search back h\:help q\:quit';export LESS
LPDEST=laser_q2;export LPDEST

#*****************************************************************************
# Treat unset parameters as an error when substituting.
# Don't mess with this unless you're a guru.
#*****************************************************************************
set +u

#*****************************************************************************
# Make it so your terminal is not open to talk requests and placement of 
# comments on your screen by other users. Change this line to 'mesg y' if
# you want to be open to talk requests by default. Otherwise, you can type
# 'mesg y' within a session to temporarily open yourself for talk requests.
#*****************************************************************************
mesg n

#*****************************************************************************
# Set up shell for vi-style command line editing (i.e. recalling commands with
# ESC-k, and using vi editor keystrokes to edit command lines).) If you prefer,
# you can replace 'vi' with 'emacs' for emacs-style command line editing (i.e.
# recalling commands with control-P, and using emacs editor keystrokes to edit
# the command line.
#*****************************************************************************
set -o vi

#*****************************************************************************
# Define user prompt to show hostname and current directory.
# This can be changed to anything.
# Change it to 
#
#    PS1 = 'GET TO WORK, BOZO!! ' 
#
# if you want the command prompt to repeatedly insult you.
#*****************************************************************************
PS1='cwis:$PWD
$ '

#****************************************************************************
# Create custom commands. All can be removed/altered *except* 'printers.
# Feel free to create your own custom commands.
# The command 'printers' is necessary for the proper functioning of the cwis
#   printer-choosing utility. The 'printers' program changes the line that 
#   sets default printer queue in this file, and this file gets "run" again 
#   to load the new value into the user environment.
# The command 'more' is altered to call the more capable 'less' pager. Disable
#   this alias if you want to use the 'more' pager.
# The command 'ls' is set up to identify executable
#    files with an * and directories with a /. Remove this alias if you want
#    the ls command to behave normally, i.e. without the * and /.    
# The command 'edit' is set up to call default editor (see EDITOR=... above).
# The command 'oldmenu' brings up the old cwis menus.
# The command 'logout' calls the unix command 'exit' to log out.
# The command 'webperms' sets up file permissions to be world-readable, for
#     web publishing.
# The command 'regperms' returns file permissions to readable by user only.
#****************************************************************************
alias printers="/share/gen/bin/printers;. $HOME/.shrc"
alias more="less"
alias ls="ls -F"
alias dir="ls -F"
alias edit="$EDITOR"
alias oldmenu=". /usr/local/bin/cwis2"
alias logout="exit"
alias quit="exit"
alias bye="exit"
alias log="exit"
alias webperms="umask 022;chmod -R a+r $HOME/public_html"
alias regperms="umask 077"


previous
section   next section   upper level