LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What are PS1, PS2, PS4 variables for? (http://www.linuxquestions.org/questions/linux-newbie-8/what-are-ps1-ps2-ps4-variables-for-610061/)

muazfarooqaslam 12-31-2007 12:19 AM

What are PS1, PS2, PS4 variables for?
 
Hi,

Can somebody please tell me what are the following variables for and how are these working

PS1=[\u@\h \W]\$
PS2=>
PS4=+

In PS1, what are "\u", "\h" and "\W"?

thnaks

Uncle_Theodore 12-31-2007 12:24 AM

For \u \h and others look here
http://tldp.org/HOWTO/Bash-Prompt-HO...sequences.html
For PS1, PS2, PS3 and PS4, type ni a terminal
man bash
when the man page comes up, hit the slash key / and type "PS2" without quotes. So it looks like this
/PS2
then hit enter. PS1 describes your prompt.

muazfarooqaslam 12-31-2007 12:48 AM

thanks, it helped. Still a little confused about PS4. Can u please help with that.

Uncle_Theodore 12-31-2007 01:00 AM

PS4 is the symbol that marks executed lines in a traced script. Let me give you a little example

Code:

#!/bin/bash

set -x    #we're going to trace execution of this script

ls
pwd
uname -a

#save this a script1.sh, make it executable with chmod u+x script1.sh
#and run from  command line. Then, change PS4 and run again


deepumnit 12-31-2007 01:24 AM

Well, the terminal prompt also includes the path of the directory. This is annoying sometimes. I can set it to my choice by using PS!="my-choice", but how can I set it permanently? I mean, if I close the terminal and open it again, I should be able to see the previously set value.

Uncle_Theodore 12-31-2007 01:30 AM

Quote:

Originally Posted by deepumnit (Post 3006351)
Well, the terminal prompt also includes the path of the directory. This is annoying sometimes. I can set it to my choice by using PS!="my-choice", but how can I set it permanently? I mean, if I close the terminal and open it again, I should be able to see the previously set value.

Create a file called .bashrc in your home directory if it doesn't exist already. It should start with a dot, so it's a hidden file.
In it, type the command
export PS1="whatever_you_want"
Don't forget to put an empty line at the end of the script.
That's it.

brianmcgee 12-31-2007 01:44 AM

And don't forget to check your prompt string. It is even more annoying if you forgot to escape some portion (for example if you choose to colorize the prompt).

In such cases if you use the bash, weird things may happen. For example that your prompt is suddenly only half displayed or characters of commands' outputs are misplaced and so on.

archtoad6 01-03-2008 07:19 PM

http://en.wikipedia.org/wiki/ANSI_escape_code might be helpful in learning how to add color to prompt strings.

deepumnit 01-03-2008 07:57 PM

Yeah, I have done all that. Thanks. I have changed it for root too, including color.


All times are GMT -5. The time now is 04:24 AM.