Changing prompt and echo statement colours?

T. 'Nifty New Hat' Mitchell mitch48 at sbcglobal.net
Wed Jun 16 03:07:59 UTC 2004


On Mon, Jun 14, 2004 at 03:07:00PM +0200, Alexander Dalloz wrote:
> Am Mo, den 14.06.2004 schrieb Chadley Wilson um 14:13:
> 
> > I would like to have a message displayed when users open the terminal.
> > This I can do! But.
....
> http://www.faqs.org/docs/Linux-HOWTO/Bash-Prompt-HOWTO.html

Did this URL move/break?  Anyhow since it looks broken at this moment.

Two quick reminders.

In the .bash-* files remember to verify that this is an interactive
tty (pseudo terminal session).  Many scripts, cronjobs, remote user,
ssh user stuff will BREAK if bash is noisy when it should be quiet.

Also test the $TERM environment variable and verify
that this is a terminal that supports the magic you want.
Have a default that makes sense... there are more than 1300
terminals described in the termcap data base you will not get
them all so focus on the one or two you care about.

Since this is an international list I should add that language 
and character sets can be important.  If things look broken 
and you get stuck language and character variables too.

Take /etc/bashrc as a starting place.  Note that two things are
checked... Interactive and $TERM=xterm.  If users are at the 
end of a wyse50, vt100 or some other terminal/ emulation recheck
this stuff.

    ================ snip =======================
    # are we an interactive shell?
    if [ "$PS1" ]; then
	case $TERM in
	    xterm*)
		    if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
			    PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
		    else
		    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
		    fi
    ================ snip =======================

Other shells (ksh, csh, tcsh) test for an interactive session
differently.  Note that csh and tcsh may want $term not $TERM.  The
escape sequences are specific to the terminal program, RTFM.

Note the subtle change from $ to # as a user switches from 
a normal user to root (UID=0).  Keep this small change intact.


-- 
	T o m  M i t c h e l l 
	/dev/null the ultimate in secure storage.





More information about the fedora-list mailing list