.kshrc 文件

用途

包含定制 Korn shell 环境的 shell 脚本。

描述

$HOME/.kshrc 文件是定制 Korn-shell 环境的 shell 脚本。 此 .kshrc 脚本通常包含用于定制 Korn-shell 环境的环境变量,命令别名和函数定义的列表。

每次启动 Korn shell 程序的新实例时, ksh 命令都会检查 $HOME/.profile 文件中设置的 ENV 环境变量的值。 如果 ENV 环境变量包含现有可读文件的名称,那么 ksh 命令将此文件作为脚本运行。 根据约定,此文件名为 $HOME/.kshrc。 您可以使用其他名称,但必须将 ENV 环境变量设置为指向该环境变量。

每次启动交互式 shell 或 shell 程序时, $HOME/.kshrc 文件都会运行。 对于所有标准输出 (stdout) , $HOME/.kshrc 文件中的命令不得采用允许您在内核级别执行以下操作的 tty 子系统环境: 进程管理,行编辑和会话管理。 在写入 stdout 之前,请确保 shell 是交互式的。 stdout 中的意外字符可能会导致从 Korn-shell 调用的程序发生故障。

示例

以下是一个特定系统上的 .kshrc 脚本的样本。 .kshrc 文件的内容可能显着不同。

# @(#).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 [[ $- = *i* ]]; then
if [ -s "$MAIL" ]       # This is at Shell startup. In
then echo "$MAILMSG"    # normal operation, the Shell checks
fi                      # periodically.
fi

# aixterm window title

if [[ $- = *i* ]]; then
[[ "$TERM" = "aixterm" ]] && echo "\033]0;$USER@${HOSTNAME%t1}\007"
fi

# 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

文件

描述
/etc/environment 包含系统范围的环境变量定义。
/etc/profile 包含系统范围的环境定制。
$HOME/.kshrc 设置 Korn shell 程序的每个启动的用户环境。
$HOME/.profile 包含特定于用户的登录初始化。