1

I can't change de PS1 prompt value of the terminal emulator of Linux Mint 19.2 with Cinnamon. It only works for logins made on the console (F1 to F6).

The last lines of .profile file:

export PS1='my-customized-prompt $'
export PSCOPY=$PS1

After restarting Cinnamon (I've tried also restarting the computer): It seems something else, after .profile, is changing the PS1 value, like the terminal emulator or any other bash "feature".

luc@lucmint:~$ echo $PSCOPY
my-customized-prompt $
luc@lucmint:~$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
luc@lucmint:~$ 

However, when I run bash from command line with "-l" argument or change the user with su command, it works:

luc@lucmint:~$ bash -l
my-customized-prompt $logout
luc@lucmint:~$ su - luc
Password: 
my-customized-prompt $

What's going on? Who is overriding the PS1 variable when the terminal emulator is open? And how to prevent it?

EDIT:

All hidden files in the home directory:

$ ls -ld  ~/.*
drwxr-xr-x 30 luc  luc   4096 Aug 27 14:44 /home/luc/.
drwxr-xr-x  3 root root  4096 Aug 26 14:27 /home/luc/..
-rw-------  1 luc  luc   4706 Aug 27 14:42 /home/luc/.bash_history
-rw-r--r--  1 luc  luc    220 Aug 26 14:27 /home/luc/.bash_logout
-rw-r--r--  1 luc  luc   3771 Aug 27 14:00 /home/luc/.bashrc
drwx------ 10 luc  luc   4096 Aug 26 16:36 /home/luc/.cache
drwxrwxr-x  4 luc  luc   4096 Aug 26 15:25 /home/luc/.cinnamon
drwxr-xr-x 14 luc  luc   4096 Aug 26 16:36 /home/luc/.config
-rw-r--r--  1 luc  luc     27 Aug 26 14:36 /home/luc/.dmrc
drwx------  2 luc  luc   4096 Aug 26 14:36 /home/luc/.gconf
-rw-r--r--  1 luc  luc    112 Aug 26 18:06 /home/luc/.gitconfig
drwx------  3 luc  luc   4096 Aug 26 16:36 /home/luc/.gnome
drwx------  3 luc  luc   4096 Aug 26 14:36 /home/luc/.gnupg
-rw-r--r--  1 luc  luc    245 Aug 26 18:18 /home/luc/.gtkrc-2.0
-rw-r--r--  1 luc  luc    516 Aug 26 14:27 /home/luc/.gtkrc-xfce
-rw-------  1 luc  luc   5470 Aug 27 14:43 /home/luc/.ICEauthority
drwxrwxr-x  2 luc  luc   4096 Aug 26 16:33 /home/luc/.icons
drwxr-xr-x  4 luc  luc   4096 Aug 26 17:53 /home/luc/.java
-rw-------  1 luc  luc     32 Aug 27 14:20 /home/luc/.lesshst
drwx------  3 luc  luc   4096 Aug 26 14:36 /home/luc/.local
drwx------  5 luc  luc   4096 Aug 26 15:04 /home/luc/.mozilla
drwxr-xr-x  7 luc  luc   4096 Aug 26 15:49 /home/luc/.nbi
drwxr-xr-x  3 luc  luc   4096 Aug 26 15:54 /home/luc/.netbeans
drwx------  3 luc  luc   4096 Aug 26 16:36 /home/luc/.pki
-rw-r--r--  1 luc  luc    938 Aug 27 14:44 /home/luc/.profile
drwx------  2 luc  luc   4096 Aug 26 16:49 /home/luc/.ssh
-rw-r--r--  1 luc  luc      0 Aug 26 14:40 /home/luc/.sudo_as_admin_successful
drwxrwxr-x  3 luc  luc   4096 Aug 26 18:19 /home/luc/.themes
-rw-r-----  1 luc  luc      5 Aug 27 14:43 /home/luc/.vboxclient-clipboard.pid
-rw-r-----  1 luc  luc      5 Aug 27 14:43 /home/luc/.vboxclient-display.pid
-rw-r-----  1 luc  luc      5 Aug 27 14:43 /home/luc/.vboxclient-draganddrop.pid
-rw-r-----  1 luc  luc      5 Aug 27 14:43 /home/luc/.vboxclient-seamless.pid
-rw-------  1 luc  luc   8268 Aug 27 14:44 /home/luc/.viminfo
-rw-------  1 luc  luc     52 Aug 27 14:43 /home/luc/.Xauthority
-rw-rw-r--  1 luc  luc    131 Aug 26 18:28 /home/luc/.xinputrc
-rw-------  1 luc  luc  19039 Aug 27 14:44 /home/luc/.xsession-errors
-rw-------  1 luc  luc  97892 Aug 27 14:42 /home/luc/.xsession-errors.old
0

Bash reads .profile only from login shells, for other interactive shells it reads .bashrc instead. (Same for /etc/profile and /etc/bash.bashrc). On many systems, including Debian, the default /etc/bash.bashrc sets PS1, so for non-login shells that's what gets used.

Your terminal emulator probably runs the shell as a non-login shell, though at least some can be configured to run a login shell instead. E.g. Gnome terminal should have a "run command as a login shell" checkbox, and if the emulator lets you change the command it invokes, you could use /bin/bash -l (the -l or --login marks a login shell).

If you didn't set PS1 in one of the bashrc files, a shell that was started without PS1 in the environment would end up with the default PS1, giving something like bash-4.4$, so it's probably safest to set PS1 in bashrc.

Also note that if the shell is started as a login shell, it will not read bashrc by itself. That's why the profile files on e.g. Debian do that explicitly.

Related:

| improve this answer | |
  • How can it set the variable PSCOPY at the end of .profile with the value of PS1 also set in .profile (see my test), but later get the value set in .bashrc if bashrc is being sourced at the beginning of .profile? – Luciano Aug 27 '19 at 18:05
  • @Luciano, right, if a login shell runs first, it reads .profile, where you export some variables. Those would then be seen by any child processes, including interactive non-login shells. But they, in turn, would run .bashrc (and friends), possibly overriding some of those variables. So PSCOPY may just be inherited from when .profile originally is processed. In any case, that PS1 with the debian_chroot parts looks a lot like what bashrc in Debian sets, so I'd suggest looking through /etc/bash.bashrc and ~/.bashrc. – ilkkachu Aug 27 '19 at 18:28
  • I've just found why it happens and how to fix it, it's the gnome-terminal behavior, it inherits .profile settings loaded once in the current session, as you said. But it can be changed checking the option "run command as a login shell". What about improving your answer adding it? unix.stackexchange.com/a/307999/114939 – Luciano Aug 27 '19 at 18:36
  • @Luciano, yep, added – ilkkachu Aug 27 '19 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.