Exporting $PS1.

Ag. Hatzimanikas a.hatzim at gmail.com
Mon Mar 12 13:08:29 PDT 2007


On Κυρ, Μάρ 11, at 01:32 Dan Nicholson wrote:
> 
> I got the same problems when playing around with dash, but I'd never
> given it much thought. I think this is a good point and I'm gonna
> change all my shell setting files to not export PS1.
> 

Exporting PS1 using bash as my login shell,made my zsh prompt unreadable.
I know for sure that it can cause problems with the tab completion.

Thus the book should be updated and that is the small first attachment 
hopefully will do.


A small note that maybe worths considering.

I would rather see a different color prompt for the root (red) and for 
user (green maybe) - for obvious reasons. 

A simple construct like the following that can be placed to the 
/etc/bashrc, it should do the job.

if [[ ${EUID} == 0 ]] ; then
	PS1='\e[0;31m\u@\h:\e[0;39m\w\$ '
	else
	PS1='\e[0;32m\u@\h:\e[0;39m\w\$ '
fi

It's same PS1 that is in the Book but with added colors.
Please check the PS1 syntax if it is right or perhaps supply a better one if
you think there is one, because I don't care enough about bash to be honest.
That is the second patch about. 
Do as you like, either way is fine by me.
-------------- next part --------------
Index: postlfs/config/profile.xml
===================================================================
--- postlfs/config/profile.xml	(revision 6665)
+++ postlfs/config/profile.xml	(working copy)
@@ -141,7 +141,7 @@
 export HISTSIZE=1000
 export HISTIGNORE="&:[bf]g:exit"
 #export PS1="[\u@\h \w]\\$ "
-export PS1='\u@\h:\w\$ '
+PS1='\u@\h:\w\$ '
 
 for script in /etc/profile.d/*.sh ; do
         if [ -r $script ] ; then
@@ -396,7 +396,7 @@
 # addendum.]
 
 #export PS1="[\u@\h \w]\\$ "
-export PS1='\u@\h:\w\$ '
+PS1='\u@\h:\w\$ '
 
 # End /etc/bashrc</literal>
 EOF</userinput></screen>
-------------- next part --------------
Index: postlfs/config/profile.xml
===================================================================
--- postlfs/config/profile.xml	(revision 6665)
+++ postlfs/config/profile.xml	(working copy)
@@ -141,7 +141,7 @@
 export HISTSIZE=1000
 export HISTIGNORE="&:[bf]g:exit"
 #export PS1="[\u@\h \w]\\$ "
-export PS1='\u@\h:\w\$ '
+PS1='\u@\h:\w\$ '
 
 for script in /etc/profile.d/*.sh ; do
         if [ -r $script ] ; then
@@ -395,8 +395,11 @@
 # PS1 Environment Variable for a great case study behind this script
 # addendum.]
 
-#export PS1="[\u@\h \w]\\$ "
-export PS1='\u@\h:\w\$ '
+if [[ ${EUID} == 0 ]] ; then
+        PS1='\e[0;31m\u@\h:\e[0;39m\w\$ '
+else
+        PS1=PS1='\e[0;32m\u@\h:\e[0;39m\w\$ '
+fi
 
 # End /etc/bashrc</literal>
 EOF</userinput></screen>


More information about the blfs-dev mailing list