[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Where is Bash Prompt Set??



On Thu, Feb 11, 2010 at 10:20:47PM -0600, Stan Hoeppner wrote:
> It works for me.  I use this:
> 
> /root/.bashrc
> export PS1="$(tput setaf 1)[\T]$(tput setaf 1)[\u@\h]$(tput sgr0)\w$ "
> 
> /home/stan/.bashrc
> if [ "$PS1" ]; then
>    PS1="$(tput setaf 2)[\T]$(tput setaf 2)[\u@\h]$(tput sgr0)\w$ "
> fi

The problem with that is, you are only invoking it on login.
This together with

> CTRL-D is new to me.  Thanks for the trick.

suggests you are logging from your root user back into your
normal user, never logging out of these shells, and the
older shell processes are hanging around, like this:

    $ ps
      PID TTY          TIME CMD
    18672 pts/0    00:00:00 bash
    18689 pts/0    00:00:00 ps
    $ su -
    Password: 
    ra:~# ps
      PID TTY          TIME CMD
    18690 pts/0    00:00:00 su
    18700 pts/0    00:00:00 bash
    18704 pts/0    00:00:00 ps
    ra:~# su - jon
    Password: 
    $ ps
      PID TTY          TIME CMD
    18672 pts/0    00:00:00 bash
    18705 pts/0    00:00:00 su
    18720 pts/0    00:00:00 bash
    18739 pts/0    00:00:00 ps

What you really want to do is execute some code as root on
logout. One hacky way to do it is to call reset in root's
logout script:

    $ sudo su -
    root promptroot@~# cat .bash_login
    export PS1='root prompt\[\033[0;31m\u@\w\$\033[0;30m \]'
    root promptroot@~# cat .bash_logout
    reset
    root promptroot@~# 
    <screen clears>
    $ 

This is a bit slow, mind, if you really want to change the
text colour for the root user then you should "unwind" the
control characters instead by preserving the older PS1 and
keeping track of which control sequences you've "opened":

    ~root/.bash_login:
        export OLDPS1="$PS1"
        export PS1="whatever you want"
    ~root/.bash_logout:
        echo "control chars that reset the text colours"
        export PS1="$OLDPS1"

-- 
Jon Dowland

Attachment: signature.asc
Description: Digital signature


Reply to: