Changing the shell prompt

Hi,

I want to change the shell prompt, using the cd command.

I have a shell prompt like this -

 
p78-mfx(dgaw1078/9781)$ 

Now i do this -

 
p78-mfx(dgaw1078/9781)$ cd log4j

here the shell prompt should change like this -

 
p78-mfx(dgaw1078/9781)log4j$

Could someone help me on this.

Regards
Arun

What is the value of PS1 now?

echo $PS1

For the current directory:

PS1='$PWD $ '

Modify this to include the other stuff in your current PS1.

Hi Scott,

Wat is PS1? Could you please explain me in detail?

I tried with this -

PS1='$PWD $ '
echo $PS1

But i'm getting $PWD $ as the result.

Regards
Arun

That's the right result! And now when you change directory, the prompt will change.

PS1 is described in the man page, in this case from KSH:

PS1    The  value of this variable is expanded for parameter expansion, command substitution, and arith-
                     metic substitution to define the primary prompt string which by default is ``$''.  The  character
                     !   in  the primary prompt string is replaced by the command number (see Command Re-entry below).
                     Two successive occurrences of !  will produce a single !  when the prompt string is printed.

Setting PS1 in this way is only temporary. Set (or modify) it in your $HOME/.profile to make it permanent, so it's there each time you log in.

There's not much to my prompt, or .profile, but I set in there:

$ cat .profile
alias ll='ls -al'
set -o vi
export EDITOR=vi
PATH=$PATH:/Users/scott/bin
PS1='$PWD $ '

Depending on your system, the default PS1 could be defined somewhere in /etc: /etc/profile, /etc/environment, /etc/bashrc, etc.

Hi
which is the shell you are working on/

Guru.

Hi Scott,

Thanks!!! Its working fine...

---------- Post updated at 07:00 AM ---------- Previous update was at 06:59 AM ----------

Hi Guru,

I'm using C shell
Regards
Arun

Thanks... This link is really useful!!!