Bash Question

Chris F.A. Johnson cfaj-uVmiyxGBW52XDw4h08c5KA at public.gmane.org
Wed Mar 5 17:01:46 UTC 2008


On Wed, 5 Mar 2008, Slackrat wrote:

> I have a problem with the prompt colours in Bash 3.1
>
> I have slackware 11.0 with no gnome or kde saving the qt libraries
> necessary to run the Opera browser since Opera doesn't like the
> libs with my qt 4.3.4 which is not a standard slack package.
>
> The relevant section of /etc/profile is listed below.
>
> The user accounts all display the assigned colours upon login as
> does root.
>
> Upon opening an rxvt terminal from the Fluxbox menu, "su -" correctly
> gives a red prompt
>
> But opening an "su" terminal, I am presented with a plain black prompt
> " bash-3.1#" and "echo $PS1" gives "\s-\v\$" with "echo $UID" giving
> "0"

    Without the hyphen, su does not source any files, it just changes
    the effective UID.

> I did want the magenta prompt for a "su" terminal that did not inherit
> root's environment, although I do have black one which admittegly is a
> different colour, but the prompt is not what I want and in
> /etc/profile I set default to '' PS1="\e[0;35m[\u@\h \W]\$ \e[m " ''
> (colour magenta)

    You have to set it manually.

> I need to run FileRunner as su since "su -" can't get a display

    Use the command "xhost localhost" before doing "su -".

> Does anyone have a Idea how I might change what the bash prompt
> displays and the colour it uses please?
>
> /etc/profile
>
> # Set a default shell prompt:
> PS1="\e[0;35m[\u@\h \W]\$ \e[m "  # COLOR DEFAULTS TO MAGENTA

    To preserve spacing on the command line, surround the non-printing
    characters with "\[" and "\]":

PS1="\[\e[0;35m\][\u@\h \W]\$ \[\e[m\] "

> if [ "$SHELL" = "/bin/pdksh" ]; then
> PS1='! $ '
> elif [ "$SHELL" = "/bin/ksh" ]; then
> PS1='! ${PWD/#$HOME/~}$ '
> elif [ "$SHELL" = "/bin/zsh" ]; then
> PS1='%n@%m:%~%# '
> elif [ "$SHELL" = "/bin/ash" ]; then
> PS1='$ '
> fi
>
> if ( [ $UID -eq 0 ] ); then
>         PS1="\e[0;31m[\u@\h \W]\$ \e[m "  # COLOR RED
> fi
>
> if ( [ $UID -eq 1000 ] ); then
>         PS1="\e[0;34m[\u@\h \W]\$ \e[m "  # USER inconnu COLOR BLUE
> fi
>
> if ( [ $UID -eq 1001 ] ); then
>         PS1="\e[0;36m[\u@\h \W]\$ \e[m "  # USER listserv COLOR CYAN
> fi
>
> if ( [ $UID -eq 1002 ] ); then
>         PS1="\e[0;32m[\u@\h \W]\$ \e[m "  # USER tanya COLOR GREEN
> fi
>
>
>

-- 
    Chris F.A. Johnson, webmaster         <http://woodbine-gerrard.com>
    ========= Do not reply to the From: address; use Reply-To: ========
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list