ksh for bash users
What are my options?
You can switch to BASH if you are very familiar with BASH, however it is recommended to stick with KSH as KSH is more POSIX compliant.
That said, you can also make KSH behave more like BASH, which is more preferable than switching over to BASH.
I want to switch to bash
If you prefer bash,
$ chsh -s /usr/local/bin/bash username
Replace username
with your real username.
Log out and log back in to make your default shell bash.
How can I make ksh behave like bash?
Edit your ~/.profile to declare the HOSTNAME variable, as the actual hostname is stored within /etc/myname. Then, you want to make sure that your ~/.profile reads its environment from your ~/.kshrc. So your ~/.profile should look something like this,
# $OpenBSD: dot.profile,v 1.5 2018/02/02 02:29:54 yasuoka Exp $
#
# sh/ksh initialization
PATH=$HOME/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/games
export PATH HOME TERM
HOSTNAME="$(cat /etc/myname)"
ENV="$HOME/.kshrc"; export ENV
Once you have that down, it is now time to edit your ~/.kshrc file.
function _cd {
\cd "$@"
PS1=$(
print -n "$LOGNAME@$HOSTNAME:"
if [[ "${PWD#$HOME}" != "$PWD" ]]; then
print -n "~${PWD#$HOME}"
else
print -n "$PWD"
fi
print "$ "
)
}
alias cd=_cd
cd "$PWD"
Implement command history
"For the arrow keys, you can put this into your the .kshrc file [(pdksh and mksh both use .mkshrc, not .kshrc)] in your home directory:
set -o emacs
alias __A=`echo "\020"` # up arrow = ^p = back a command
alias __B=`echo "\016"` # down arrow = ^n = down a command
alias __C=`echo "\006"` # right arrow = ^f = forward a character
alias __D=`echo "\002"` # left arrow = ^b = back a character
alias __H=`echo "\001"` # home = ^a = start of line
alias __Y=`echo "\005"` # end = ^e = end of line
How do I change my password?
$ passwd
Changing password for $user
Old password:
New password:
Retype new password:
$