I am using KornShell (ksh) on Solaris and currently my PS1 env var is:
PS1="${HOSTNAME}:\${PWD} \$ "
And the prompt displays: hostname:/full/path/to/current/directory $
However, I would like it to display: hostname:directory $
In other words, how can I display just the hostname and the name of the current directory, i.e. tmp
or ~
or public_html
etc etc?
Try this:
More information on: How to: Change / Setup bash custom prompt, I know you said ksh, but I am pretty sure it will work.
and...
if you work between two shells for most of your effort [ksh and bourne sh] and desire a directory tracking display on your command line then PWD can be substituted easily in ksh and if you use /usr/xpg4/bin/sh for your sh SHELL, it will work there as well
Okay, a little old and a little late, but this is what I use in Kornshell:
This makes a prompt that's equivalent to
PS1="\u@\h:\w\n$ "
in BASH.For example:
I like a two line prompt because I sometimes have very long directory names, and they can take up a lot of the command line. If you want a one line prompt, just leave off the "\n" on the last print statement:
That's equivalent to
PS1="\u@\h:\w$ "
in BASH:It's not quite as easy as setting up a BASH prompt, but you get the idea. Simply write a script for
PS1
and Kornshell will execute it.For Solaris and other Older Versions of Kornshell
I found that the above does not work on Solaris. Instead, you'll have to do it the real hackish way...
In your
.profile
, make sure thatENV="$HOME/.kshrc"; export ENV
is set. This is probably setup correctly for you.In your
.kshrc
file, you'll be doing two things_cd
. This function will change to the directory specified, and then set your PS1 variable based upon your pwd.cd
to run the_cd
function.This is the relevant part of the
.kshrc
file:This will set your prompt as the equivelent BASH
PS1="\u@\h:\w$ "
. It isn't pretty, but it works.ENV=~/.kshrc, and then in your .kshrc:
Brad