LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/)
-   -   how to change the shell prompt globally (https://www.linuxquestions.org/questions/ubuntu-63/how-to-change-the-shell-prompt-globally-4175571656/)

mfoley 02-07-2016 01:06 PM

how to change the shell prompt globally
 
I want to change the bash shell prompt. So far, every post I've seen on this discusses changing the user's .bashrc or .bash_profile. That's not what I want. I want to change the prompt globally for all users.

I've modified the PS1 env. variable in /etc/profile, but that does nothing.

Where do I do this?

rknichols 02-07-2016 01:57 PM

Changing /etc/profile isn't going to affect shells that are already running. Only newly spawned login shells will be automaticlly reading that file. Nor will setting PS1 in /etc/profile affect any users that set their own PS1 in their .bash_profile or .bashrc files.

mfoley 02-07-2016 02:12 PM

I figured it out. PS1 is set all over the place (sometimes I think Ubuntu is going "Microsoft" on us!). In order to get a common, unified PS1 for this system, I did the following:

1. set the promt I want in /etc/profile:

Code:

1  if [ "$PS1" ]; then
 2    if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
 3      # The file bash.bashrc already sets the default PS1.
 4      # PS1='\h:\w\$ '
 5      if [ -f /etc/bash.bashrc ]; then
 6        . /etc/bash.bashrc
 7      fi
 8    fi
 9  ##  else
10      if [ "`id -u`" -eq 0 ]; then
11  #      PS1='# '
12  PS1='$SHLVL \t \u@\h:\w\n# '
13      else
14  #      PS1='$ '
15  PS1='$SHLVL \t \u@\h:\w\n$ '
16      fi
17  ##  fi
18  fi

I added lines 12 and 15 (my desired prompts) and commented out 9, 11, 14 and 17.

/etc/bash.bashrc is sourced by /etc/profile (line 6), and it too wants to set PS1. I commented out the PS1 setting in this file, which is the 19th line in my version:

Code:

# set a fancy prompt (non-color, overwrite the one in /etc/profile)
# PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

Finally, $HOME/.bashrc also sets PS1. I commented out lines 59-73, except 64:

Code:

    59  #if [ "$color_prompt" = yes ]; then
    60  #    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    61  #else
    62  #    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    63  #fi
    64  unset color_prompt force_color_prompt
    65
    66  # If this is an xterm set the title to user@host:dir
    67  #case "$TERM" in
    68  #xterm*|rxvt*)
    69  #    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    70  #    ;;
    71  #*)
    72  #    ;;
    73  #esac

I've also made this same change in /etc/skel/.bashrc so it propagates for newly added users.

mfoley 02-07-2016 10:57 PM

Wait! There's more! gnome-terminal does not source /etc/.profile (see here: http://askubuntu.com/questions/40287...-being-sourced). To get it to do so, (in the menu bar) Edit > Profile Preferences > Command > Check: "Run command as a login shell"

Who knew that setting the shell prompt could evolve into such complexity!

rknichols 02-08-2016 09:56 AM

You could just put the setting in /etc/bashrc, which would get sourced by non-login shells too.


All times are GMT -5. The time now is 06:03 AM.