Bash Question

Giles Orr gilesorr-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Wed Mar 5 15:26:02 UTC 2008


On Wed, Mar 5, 2008 at 7:26 AM, Slackrat <tlug-MOdoAOVCFFcswetKESUqMA at public.gmane.org> 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"
>
>  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)
>
>  I need to run FileRunner as su since "su -" can't get a display
>
>  Does anyone have a Idea how I might change what the bash prompt
>  displays and the colour it uses please?

As the author of the "Bash Prompt HOWTO" I'm probably supposed to know
stuff like this ...  Unfortunately, which terms source which Bash
startup files under which circumstances is something I haven't really
dug in to.

My guess here is that "su" (without the dash) is sourcing
/etc/bash.bashrc (Debian's choice of name - I think this varies by
distro, look at "man bash" for a FILES section) rather than
/etc/profile (which is sourced for anything that is considered a
"login shell" which "su" probably is not).  What I'd suggest is doing
something similar to what I have: on my system both /etc/profile and
/etc/bash.bashrc source a file called /etc/bash.giles which includes
my aliases, functions, and prompts.  You might try putting the prompt
you want to go with your su command in /etc/bash.bashrc if you don't
want to create a new layer of obfuscation.  :-)  But then you have two
places to dig about if you want to change the appearance of the prompt
and keep it consistent.

>  /etc/profile
>
>  # Set a default shell prompt:
>   PS1="\e[0;35m[\u@\h \W]\$ \e[m "  # COLOR DEFAULTS TO MAGENTA
>  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

-- 
Giles
http://www.gilesorr.com/
gilesorr-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
--
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