As a general rule, put idempotent things (e.g., setting the PATH
environment variable) in ~/.profile
, but put things that must be performed on a per-shell/subshell basis (e.g., aliases; HISTFILE
and ENV
and PS1
environment variables) in ~/.kshrc
(or whatever your ${ENV}
is set as in ~/.profile
). Then you will have your aliases proper set afresh in each subshell of ksh.
~/.profile
if [ -n "$BASH_VERSION" ]
then
if [ -f "$HOME/.bashrc" ]
then
. "$HOME/.bashrc"
fi
elif [ -n "$KSH_VERSION" ]
then
if [ -f "$HOME/.kshrc" ]
then
. "$HOME/.kshrc"
fi
elif [ -n "$ZSH_VERSION" ]
then
if [ -f "$HOME/.zshrc" ]
then
. "$HOME/.zshrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ]
then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ]
then
PATH="$HOME/.local/bin:$PATH"
fi
~/.kshrc
hostname=/bin/hostname
ksh=/bin/ksh
stty=/bin/stty
tput=/usr/bin/tput
tty=/usr/bin/tty
whoami=whoami
bold=$(${tput} bold)
dim=$(${tput} dim)
bgblue=$(${tput} setab 4)
bgcyan=$(${tput} setab 6)
bggreen=$(${tput} setab 2)
bgmagenta=$(${tput} setab 5)
bgred=$(${tput} setab 1)
bgwhite=$(${tput} setab 7)
bgyellow=$(${tput} setab 3)
fgblue=$(${tput} setaf 4)
fgcyan=$(${tput} setaf 6)
fggreen=$(${tput} setaf 2)
fgmagenta=$(${tput} setaf 5)
fgred=$(${tput} setaf 1)
fgwhite=$(${tput} setaf 7)
fgyellow=$(${tput} setaf 3)
sgr0=$(${tput} sgr0)
smso=$(${tput} smso)
smul=$(${tput} smul)
rmso=$(${tput} rmso)
rmul=$(${tput} rmul)
tty_path=$(${tty})
set -o emacs
export PS1='${fgblack}${bgyellow}↑$
${sgr0}ksh${dim}${fgblue}${bggreen}$(${hostname})${sgr0}${fgwhite}${tty_path#/dev/}${sgr0}${smul}${dim}$(${whoami})${sgr0}${PWD}
$ '
export ENV=~/.kshrc
alias l='ls -AFq'
alias rd='rmdir'
alias md='mkdir'
alias ssh='ssh -X'
alias emacs-nw='emacs -nw'
alias over='_(){ cd ../$1; }; _'
alias cd..='_(){ cd ../$1; }; _'
This best practice is true of shells other than ksh as well, such as csh and bash and zsh.
(Most especially don't put incremental/nonidempotent appending or prepending of PATH
environment variable in ~/.kshrc
, but that is unrelated per se to the question here.)