1753373 Members
4991 Online
108792 Solutions
New Discussion юеВ

Re: changing the prompt

 
SOLVED
Go to solution
Sean OB_1
Honored Contributor

Re: changing the prompt

I use the following:

me=`who am i | cut -d' ' -f1`
host=`hostname`
PS1='me@$host:$PWD:# '


Allan Pincus
Frequent Advisor

Re: changing the prompt

Tom:

You got it, right on the money! Exactly what I was looking for. I formatted your expression even prettier like this:

export PS1=`hostname`:./'${PWD##*/} > '

Which returns something like this:

myServer:./lastPath > _

And it changes with each cd command.

Cool!

One question:

I've never seen the ##*/ operator, or (or is this a grep expression?) Can you explain how this is working?

Thanks a bunch!!

- Allan
A. Clay Stephenson
Acclaimed Contributor

Re: changing the prompt

If you do a man sh_posix and look under the 'Parameter Substitution' section, you will see just how this is working as well as a few other ways to use substitution.
If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor

Re: changing the prompt

This is probably what you are looking for:

export PS1='${PWD##${PWD%/*/*}/}'

Be sure you use single quotes. This will show the current directory and one level up. It's really useful for a short prompt but with a little less ambiguity than just the basename (which bin directory is it?)

BTW: The # and % constructs are specific to POSIX shells such as ksh, bash and the HP POSIX shell. It has to do with pattern matching (shortest or longest, left or right pattern). It's a bit difficult to grasp from the man pages; try a good Korn shell book.


Bill Hassell, sysadmin
Kenneth_18
Frequent Advisor

Re: changing the prompt

Just a suggestion. How about using the bash shell? PS1="\u@\h: \W \\$ " will give you the PS1 prompt of a typical linux prompt like

username@hostname current_working_directory root/non-root sysmbol.

for root a root user, it would look like similar to this:

root@hostname: / #

for a non-root user it would look similar to this:

user1@hostname: user1 $