David Jensen wrote:
> taipan67 wrote:
>>>>> 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\]"
>>>     
> I don't see \033 as preferable to \e, otherwise it looks OK.
> Perhaps the bold/bright, '1' could be dropped, most others likely don't 
> use a white on black xterm as I do.
> 
> thus:
>     NORMAL="\[\e[0m\]"
>     RED="\[\e[31m\]"
>     GREEN="\[\e[32m\]"
> 
> Maybe single quotes, though there is nothing, as is, that bash will mangle.

The single quote acts differently.  From the man page:

"Enclosing  characters  in single quotes preserves the literal value of
each character within the quotes.  A single quote may not occur between
single  quotes,  even  when preceded by a backslash."

"Enclosing  characters  in double quotes preserves the literal value of
all characters within the quotes, with the exception of $, `, and \."

In this case, using single quotes may not be a problem because the
backslashes will then be interpreted when PS1 is evaluated.

> Does anyone know why the escaped bracketing is required, it is.
> It seems "\e[1;31m" should work but the cursor position and scrolling 
> get fouled.

The bash man page again has the answer.  Under PROMPTING:

"  \[  begin  a  sequence  of  non-printing characters, which could
       be used toembed a terminal control sequence into the prompt
   \]  end a sequence of non-printing characters"

I believe this is needed to tell bash not to count these characters when
determining when to wrap a line.

>> <snip> They also define 'normal' as "\[\033[00m\]" (not sure of 
>> the difference).

> This seems incorrect to me, 00m is default mode, not a color.  It does 
> however, set the default color and attribute.  Either '\e[00m' or 
> '\e[0;39m'  seem correct.

The sequence "\e[m" could also be used.  The usual sequence I've seen is
"\e[00m". I believe "\e[0;39m" would only reset the foreground color and
not the background color.

> Reviewing this thread 
> http://linuxfromscratch.org/pipermail/blfs-dev/2007-March/016818.html
> it seems PS1 should not be exported, no decision was reached

It should not be exported because it does no good.  PS1 is reset for
each invocation.  From the bash man page:

"An  interactive  shell is one started without non-option arguments and
without the -c option whose standard input and error are both connected
to terminals (as  determined by  isatty(3)),  or  one started with the
-i option.  PS1 is set and $- includes i if bash is interactive,
allowing a shell script or a startup file to test this state."

  -- Bruce
-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to