LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-31-2007, 12:19 AM   #1
muazfarooqaslam
LQ Newbie
 
Registered: Dec 2007
Posts: 22

Rep: Reputation: 15
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
 
Old 12-31-2007, 12:24 AM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
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.
 
Old 12-31-2007, 12:48 AM   #3
muazfarooqaslam
LQ Newbie
 
Registered: Dec 2007
Posts: 22

Original Poster
Rep: Reputation: 15
thanks, it helped. Still a little confused about PS4. Can u please help with that.
 
Old 12-31-2007, 01:00 AM   #4
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
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
 
Old 12-31-2007, 01:24 AM   #5
deepumnit
Member
 
Registered: Dec 2006
Location: NOIDA, India
Distribution: Debian, SUSE, Fedora
Posts: 334
Blog Entries: 1

Rep: Reputation: 31
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.
 
Old 12-31-2007, 01:30 AM   #6
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
Quote:
Originally Posted by deepumnit View Post
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.
 
Old 12-31-2007, 01:44 AM   #7
brianmcgee
Member
 
Registered: Jun 2007
Location: Munich, Germany
Distribution: RHEL, CentOS, Fedora, SLES (...)
Posts: 399

Rep: Reputation: 40
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.
 
Old 01-03-2008, 07:19 PM   #8
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
http://en.wikipedia.org/wiki/ANSI_escape_code might be helpful in learning how to add color to prompt strings.
 
Old 01-03-2008, 07:57 PM   #9
deepumnit
Member
 
Registered: Dec 2006
Location: NOIDA, India
Distribution: Debian, SUSE, Fedora
Posts: 334
Blog Entries: 1

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


Reply

Tags
ps1



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
set variables in a bash script; ansi PS1 color script donnied Programming 4 11-21-2007 11:33 AM
Threads synchronisation problem (mutex variables and contitional variables) zahadumy Programming 6 12-07-2005 12:30 PM
PS1 variable wogga Red Hat 2 05-26-2004 05:39 PM
is there a file to configure PS1 and PS2 permanently? kiki Linux - Newbie 3 08-06-2003 10:31 PM
Shel scripting: variables pointing to variables and case Dark_Helmet Programming 5 06-08-2003 11:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration