Changing the shell prompt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing the shell prompt
# 1  
Old 05-22-2010
Changing the shell prompt

Hi,

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

I have a shell prompt like this -

Code:
 
p78-mfx(dgaw1078/9781)$

Now i do this -

Code:
 
p78-mfx(dgaw1078/9781)$ cd log4j

here the shell prompt should change like this -

Code:
 
p78-mfx(dgaw1078/9781)log4j$

Could someone help me on this.

Regards
Arun
# 2  
Old 05-22-2010
What is the value of PS1 now?
Code:
echo $PS1

For the current directory:
Code:
PS1='$PWD $ '

Modify this to include the other stuff in your current PS1.
# 3  
Old 05-22-2010
Hi Scott,

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

I tried with this -
Code:
PS1='$PWD $ '
echo $PS1

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

Regards
Arun
# 4  
Old 05-22-2010
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:
Code:
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:
Code:
$ 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.
# 5  
Old 05-22-2010
Hi
which is the shell you are working on/



Guru.
# 6  
Old 05-22-2010
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
# 7  
Old 05-22-2010
Thanks... This link is really useful!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Changing the prompt in CSH

Need assistance in changing prompt . Trying to change prompt in csh,tcsh shell . Below are the commands i tried in .cshrc and sourcing this files. set prompt = "$user@`uname -n` : ${cwd}> " #above commands works for username and hostname but cwd doesnt change directories set... (16 Replies)
Discussion started by: ajayram_arya
16 Replies

2. Shell Programming and Scripting

Changing default prompt

Hi, i was wondering if it is possible to change the default prompt for the shells that are availble on your system? For example, i want to change the prompt for the C shell from % to something like ( or ). Thanks, Nav. (7 Replies)
Discussion started by: Navs_
7 Replies

3. UNIX for Dummies Questions & Answers

Changing ubuntu prompt

Currently, when I cd to a directory I get the directory path in the command prompt, making it very long. I would like to change it so the path is not displayed. If I am in directory ~/tatsh/hstmy/test, I just want my prompt to be the last directory name as shown just below ---------- Post... (1 Reply)
Discussion started by: kristinu
1 Replies

4. UNIX for Advanced & Expert Users

Changing the password prompt

Is there any way I can change the prompt which asks for the password on a UNIX system? e.g. When I login using Telnet instead of "Password" I should get "Correct Password". Thanks, Vineet (3 Replies)
Discussion started by: vineetd
3 Replies

5. Shell Programming and Scripting

problem in changing prompt

hi all, please tell me why this 2 liner script is not working!! #!/bin/bash oldps1="$PS1" PS1="myprompt>" but when type this in terminal it works!! (7 Replies)
Discussion started by: tprayush
7 Replies

6. Solaris

Changing prompt

I currently have this as my prompt when I log in (shell is sh): PS1="`hostname ` # " My question is how do I add the current directory to that prompt? Is there a way? Thanks. (5 Replies)
Discussion started by: kjbaumann
5 Replies

7. UNIX for Dummies Questions & Answers

Changing Prompt in sh

I know no one has ever asked this before {not :D } but I am trying to set the prompt in the .profile under sh. I have tried everything I have seen on the web in regards to this, with no success. The OS is SCO Unixware 7.1.1, {not by my choice}. All the examples I see seem to be for ksh, which is... (1 Reply)
Discussion started by: jcc5169
1 Replies

8. UNIX for Dummies Questions & Answers

Changing the prompt

Phew simple question, I want to display the my directory path in prompt. Did the following in .profile PS1=`pwd` export PS! Worked, but it always points to HOME directory. When i do a cd, it doesn't change. What am i missing. Thanks (7 Replies)
Discussion started by: vibhor_agarwali
7 Replies

9. UNIX for Dummies Questions & Answers

Changing Unix Prompt

Me again, What is the difficulty to display the full directory Path before my prompt command ? (like DOS) I'm using Solaris 8 + Bash Thanks again Fabien (4 Replies)
Discussion started by: unclefab
4 Replies

10. UNIX for Dummies Questions & Answers

Changing the UNIX command prompt

I am having a hard time figuring out how to change the command prompt in my UNIX shell. I am using the bash shell, and I would like to set the prompt to show me the full path of the current working directory along with my username, I suppose... The main thing I want is the full path of the... (2 Replies)
Discussion started by: WERUreo
2 Replies
Login or Register to Ask a Question