There exist a few implementations of ksh:
- The original (or AT&T) one by David Korn with two major variants (ksh88 and ksh93) each one having different versions with a different feature set
pdksh
(the public-domain Korn shell) with a few derivatives.
zsh
. Zsh has a ksh emulation mode which it activates when called as ksh
.
You may want to use zsh as your ksh, or even switch altogether to zsh which is a much more powerful tool as an interactive shell.
If you call zsh as ksh
. You can have the prompt expansion you want by doing (add it to your $ENV
file):
setopt PROMPT_PERCENT # restore zsh prompt expansion disabled by the ksh mode
PS1='%! %~$ '
Otherwise, if you do need to stick with the AT&T or PD ones, you could aproximate it with:
PS1='! $(pwd | sed "s,^$HOME,~,")$ '
Which would work for ~
but not for ~other-user
.
Example:
$ echo ${.sh.version}
Version JM 93u+ 2012-02-29
$ PS1='! $(pwd | sed "s,^$HOME,~,")$ '
85 ~$ cd /tmp
86 /tmp$ cd
87 ~$
From a vague recollection from decades ago, it could be that ksh88 doesn't expand command substitutions inside $PS1
. In that case, you could still use some trick like:
one=1
tilde='~'
PS1='! ${tilde[0${one#${PWD##"$HOME"*}1}]}${PWD#"$HOME"}$ '
(which I've now verified works on all of ksh93u+ on Debian, ksh88i on Solaris, MirBSD ksh 40.9.20120630 (pdksh derivative) on Debian, and zsh 4.3.17 (when called as ksh
) on Debian, so I'd be surprised if there was any ksh where it didn't work)
The idea being that if $PWD
starts with $HOME
, then ${PWD##"$HOME"*}
is empty, so ${one#1}
is empty, so we get ${tilde[0]}
that is $tilde
. But if it doesn't then ${PWD##"$HOME"*}
is $PWD
, then ${one#${PWD}1}
is $one
, so we get ${tilde[1]}
which is empty as the $tilde
array as only one element.
uname -a
– jippie Oct 16 '12 at 6:42SunOS solaris 5.10 Generic_141445-09 i86pc i386 i86pc
– cornbread ninja Oct 16 '12 at 14:57