Bruce Dubbs bruce.dubbs at gmail.com
Sun Jul 29 07:58:55 PDT 2007

taipan67 wrote:
> Bruce Dubbs wrote:
>> David Jensen wrote:
>>> Moving to dev. 
>>> Ag. D. Hatzimanikas wrote:
>>>> Does this prompt (in /etc/profile) looks good to you? (it was suggested by 
>>>> David Jensen)
>>>> if [[ ${EUID} == 0 ]] ; then
>>>> 	PS1='\[\e[1;31m\]\u [ \[\e[00m\]\w \[\e[1;31m\]]\$ \[\e[00m\]'
>>>>         else
>>>> 	PS1='\[\e[1;32m\]\u [ \[\e[00m\]\w \[\e[1;32m\]]\$ \[\e[00m\]'
>>>> fi
>> This is too cryptic.  Use:
>> NORMAL="\[\033[0;39m\]"
>> RED="\[\033[1;31m\]"
>> GREEN="\[\033[1;32m\]"
>> if [[ ${EUID} == 0 ]] ; then
>>   PS1="$RED\u [ $NORMAL\w$RED ]\$ $NORMAL"
>> else
>>   PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
>> fi
>>   -- Bruce
> I've also stolen coloured PS1 values from my current Gentoo-box, & they 
> use the '\033' escape-sequence listed above, but in full, not through 
> variable-names. They also define 'normal' as "\[\033[00m\]" (not sure of 
> the difference).

\e and \033 are the same thing. They are the ASCII escape chararacter,
ESC, decimal 27, octal 33, hex 1b.

> However, Gentoo define them in /etc/bashrc, & have the line ". 
> /etc/bashrc" (that's 'full-stop' 'space' 'filename') in /etc/profile, 
> instead of a PS1 declaration. I found this to be necessary when booting 
> into my LFS system. I also have a third colour defined for 
> package-users, but that had to go in the pkgusr ~/.bashrc to work, 
> presumably because they never boot the system, they are only su'd to by 
> root.

/etc/bashrc is not a standard bash file.  It is only used if another
configuration file, e,g, /etc/profile, calls it.  BLFS follows that
convention by sourceing it from ~/.bashrc.  The dot operator in bash is
a somewhat cryptic shortcut for the bash 'source' command.  It exists
primarily for compatibility with sh.

PS1 is required by every new invocation of an interactive bash session,
so it needs to be called by ~/.bashrc or a file sourced from that.

> There are additional pre-checks for the existence of /etc/dircolors & 
> that the terminal in use supports colour. For future builds, it's my 
> intention to incorporate this into my base LFS-build, as dircolors is 
> installed by coreutils fairly early in both chapters 5 & 6 - i haven't 
> worked out the details yet...

The initialization files in BLFS are intended as starting points for you
to customize as you desire.

  -- Bruce

More information about the blfs-dev mailing list