1

I'm starting it with startx. Before that I have PS1 in my environment:

$ cat /proc/self/environ | tr '\0' '\n' | egrep '^PS'
PS1=[\u@\H \w] 
PS3=> 
PS2=> 
PS4=+ 

From inside X I get:

$ cat /proc/self/environ | tr '\0' '\n' | egrep '^PS'
PS3=> 
PS4=+ 

I checked in both GNOME and awesome. Is it expected behavior? Can I do something about it?

2
  • You'd be better using env or even set to print your environment: set | grep '^PS'. Commented Feb 28, 2015 at 14:37
  • @roaima set doesn't print only environment variables. export does, and has the advantage over env that its output is sorted. Commented Mar 1, 2015 at 2:01

2 Answers 2

1

No, X doesn't mangle environment variables. But bash does; specifically, it unsets PS1 and PS2 in non-interactive shells:

$ PS1='my PS1' PS2='my PS2' PS3='my PS3' PS4='my PS4' bash -c export |grep PS
declare -x PS3="my PS3"
declare -x PS4="my PS4"

Bash is probably executed somewhere as part of your login sequence. That's guaranteed if your /bin/sh is bash and common even if it isn't.

The prompt is a shell setting, meaningful only in interactive shells, so it doesn't make sense to export it to the environment. Set it as part of your shell's interactive initialization file .bashrc instead.

1
  • First, you must be right. I just wanted to inform you that I tried to make bash startup files as minimalistic as possible. I left only /etc/profile with exporting PS1..4. I still couldn't see PS1..2 inside X. And yes, /bin/sh is a symbolic link to /bin/bash. The second thing... I just tried to follow the idea that things that apply to the whole session are to go into /etc/profile.
    – x-yuri
    Commented Mar 1, 2015 at 14:17
-1

I'm going to assume you're running bash as your shell. If you're running something else the specifics will vary but the approach will remain much the same. To confirm your login shell, run this command: getent passwd "${USER:-$(id -nu)}" | awk -F: '{print $NF}'

I suspect that your prompt is defined in .profile or .bash_profile and is set (once) when you log in to your terminal. When you call startx and open a terminal it "knows" it's not a login session so calls .bashrc instead.

You can confirm this with the following command, the result of which you might like to reference in your Question: grep '\<PS.*=' .profile .bash_profile .bashrc

My recommendation would be to configure your GUI terminal application to force a login shell (assuming such an option exists in your installation).

As an alternative, review the files .profile, .bash_profile, and .bashrc, and move one-off startup code to a new file such as .bash_once and code that needs to be repeated for each instance of bash to a new file such as .bash_everytime. You can then source .bash_once and source .bash_everytime appropriately from the now-empty .profile or .bash_profile, and .bashrc.

2
  • I don't understand where you're getting at with this answer. Forcing a login shell in terminals would solve this particular problem, but it's a bad idea since it introduces a whole slew of other problems (like not having the prompt in shells that aren't directly invoked from the user's favorite terminal emulator). Commented Mar 1, 2015 at 2:02
  • @Gilles it was an easy option in case x-yuri wasn't familiar enough with a Linux-based system to do anything else. The approach I take on my own systems is similar to that which I described starting "As an alternative...". Commented Mar 2, 2015 at 23:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .