LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 02-07-2016, 01:06 PM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,576

Rep: Reputation: 179Reputation: 179
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?
 
Old 02-07-2016, 01:57 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
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.
 
Old 02-07-2016, 02:12 PM   #3
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,576

Original Poster
Rep: Reputation: 179Reputation: 179
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.

Last edited by mfoley; 02-07-2016 at 02:16 PM.
 
Old 02-07-2016, 10:57 PM   #4
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,576

Original Poster
Rep: Reputation: 179Reputation: 179
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!
 
Old 02-08-2016, 09:56 AM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

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


Reply

Tags
bash, prompt



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to change the login name in the shell prompt? MURIITHI P Linux - Newbie 11 04-16-2012 07:13 AM
[SOLVED] How do I permanently change my shell prompt? venom4u31 Linux - Newbie 2 11-16-2011 04:34 PM
I'd like to change the default shell prompt. lynnevan Linux - General 9 09-08-2011 08:00 AM
how do i change the current prompt in shell? prospekrisal Linux - Newbie 4 07-16-2006 10:35 AM
change the shell prompt ust Linux - Distributions 5 04-28-2005 03:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 01:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration