[lfs-support] PS1 for user lfs

Bruce Dubbs bruce.dubbs at gmail.com
Fri Apr 20 16:06:37 PDT 2012


Philippe Delavalade wrote:
> Le samedi 21 avril à 00:32, Bruce Dubbs a écrit :
>> Philippe Delavalade wrote:
>>> Le vendredi 20 avril à 23:51, Bruce Dubbs a écrit :
>>> [...]
>>>> Everything except PS1 seems OK.
>>> it's to complicated for me :-)
>>>
>>>> Did you do 4.3:  `su - lfs` 
>>> Yes, sure ! I tried three times ; the first time, I thought I forgot some
>>> thing ; so I ran `userdel` and `groupdel` and began again, this two times
>>> but the result is always the same.
>>>
>>>> The dash is needed.  PS1 is not normally set when 
>>>> starting a login shell.  We set it explicitly.  In a non-login shell, it needs 
>>>> to be reset every time, usually by setting it in ~/.bashrc.
>>> yes, that's what I do for the other users but with user lfs, I follow
>>> always exactly the book and use cut/paste for commands to avoid any typo.
>> Sure, but sometimes inadvertent errors are made.
>>
>>> While mailing on the list with you, I configure, compiled and intalled
>>> binutils and gcc (pass 1) without any problem.
>> Yes, a different PS1 prompt should not give you any problem.  I was just trying 
>> to help you figure out this minor discrepancy.
> 
> Yes, I understand and my goal is also to know why this happen because it's
> not normal.
> 
>> What happens if you just `export PS1='\u:\w\$ '`
> 
> I obtain the right prompt.
> 
> I can put this in .bashrc but the prompt, by itself, does not worry me. I'm
> just wondering why it does not go like it should.
> 
> By the way, I use to insert into the .bashrc of my different users the
> following :
> 
> if [ "$PS1" ]; then
>     _prompt_command()
>     {
> 	 local status="$?";
> 	 if [ $status != 0 ]; then
> 	     echo -n "$status " 1>&2;
> 	 fi 
>     }
>     PROMPT_COMMAND=_prompt_command
> fi
> 
> May I put these lines in the lfs .bashrc ?

Sure.  I have:

HOST=`hostname`
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
   PS1="$RED\u$NORMAL@$HOST$RED [ $NORMAL\w$RED ]# $NORMAL"
else
   PS1="\u$GREEN@$HOST$GREEN [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi

I use that for each user.

Note that ~/.bashrc does not get called when doing a normal login prompt unless 
you specifically call it in ~/.bash_profile.  That is not a part of the BOOK's 
login script.  To force a login prompt, use `/bin/bash -l`

~/.bashrc is normally called when bash is called interactively (forced by 
/bin/bash -i)

   -- Bruce




More information about the lfs-support mailing list