Why does subshell not inherit exported variable (PS1)?

Posted by amn on Super User See other posts from Super User or by amn
Published on 2013-10-21T09:51:08Z Indexed on 2013/10/21 9:59 UTC
Read the original article Hit count: 255

Filed under:
|
|

After some debugging I finally narrowed down the problem as to why my X session xterm prompt does not appear according to my PS1 setting. If I run sh -c env, it doesn't even show PS1 in the list. Why?

export PS1='test'
sh -c env # No PS1 in the list, default prompt appearance (shell name + version)

Substituting sh with bash yields same result, alas the behavior appears to be the same for both shells/modes. As far as I understood from man bash, the environment resulting from command run by shell with -c should include the exported variables. And it does - exporting FOOBAR results in FOOBAR listed in env run by subshell. It appears that the story is different if the variable is PS1 however. What is going on? I want my prompt propagated throughout the process tree and system. For matters sake, it is set in /etc/profile.d/user.sh (a file I created myself) with the following:

PS1='\u@\H \w \$ '
export PS1

I am running Arch Linux (updated yesterday.)

© Super User or respective owner

Related posts about bash

Related posts about environment-variables