.kshrc File

Purpose

Contains a shell script that customizes the Korn shell environment.

Description

The $HOME/.kshrc file is a shell script that customizes the Korn-shell environment. This .kshrc script often contains a list of environment variables, command aliases, and function definitions that customize the Korn-shell environment.

Each time you start a new instance of the Korn shell, the ksh command examines the value of the ENV environment variable set in the $HOME/.profile file. If the ENV environment variable contains the name of an existing, readable file, the ksh command runs this file as a script. By convention, this file is named $HOME/.kshrc. You can use another name, but you must set the ENV environment variable to point to it.

Note: .kshrc should never output (echo, print, or call any program that echos or prints) anything.

Examples

The following is a sample of a .kshrc script on one specific system. The contents of your .kshrc file can be significantly different.

# @(#).kshrc 1.0
# Base Korn Shell environment
# Approach:
#      shell            initializations go in ~/.kshrc
#      user             initializations go in ~/.profile
#      host / all_user  initializations go in /etc/profile
#      hard / software  initializations go in /etc/environment      
# DEBUG=y       # uncomment to report
[ "$DEBUG" ] && echo "Entering .kshrc"
set -o allexport
# options for all shells --------------------------------
# LIBPATH must be here because ksh is setuid, and LIBPATH is
# cleared when setuid programs are started, due to security hole.
LIBPATH=.:/local/lib:/lib:/usr/lib
# options for interactive shells follow-------------------------
TTY=$(tty|cut -f3-4 -d/)
HISTFILE=$HOME/.sh_hist$(echo ${TTY} | tr -d '/')
PWD=$(pwd)
PS1='
${LOGNAME}@${HOSTNAME} on ${TTY}
[${PWD}] '
# aliases
[ "$DEBUG" ] && echo "Setting aliases"
alias man="/afs/austin/local/bin/man -e less"
alias pg="pg -n -p':Page %d: '"
alias more="pg -n -p':Page %d: '"
alias cls="tput clear"
alias sane="stty sane"
alias rsz='eval $(resize)'
# mail check
if [ -s "$MAIL" ]       # This is at Shell startup.  In 
then echo"$MAILMSG"     # normal operation, the Shell checks
fi                      # periodically.
# aixterm window title
[[ "$TERM" = "aixterm" ]] && echo 
"\033]0;$USER@${HOSTNAME%t1}\007"
# functions
[ "$DEBUG" ] && echo "Setting functions"
function pid { ps -e | grep $@ | cut -d" " -f1; }
function df {
  /bin/df $* | grep -v afs;
  echo "\nAFS:";
  /usr/afs/bin/fs listquota /afs;
}
function term {
  if [ $# -eq 1 ]
  then
    echo $TERM
    TERM=$1
    export TERM
  fi
  echo $TERM
}
function back {
  cd $OLDPWD
  echo $CWD $OLDPWD
}
[ "$DEBUG" ] && echo "Exiting .kshrc"
set +o allexport

Files

Item Description
/etc/environment Contains system-wide environment variable definitions.
/etc/profile Contains system-wide environment customization.
$HOME/.kshrc Sets the user environment for each start of the Korn shell.
$HOME/.profile Contains user-specific logon initialization.