Please co开发者_运维百科nsider the following /root/.profile:
export PS1=value1
export x=value2
How come the login shell shows the expected prompt (and $x as value2), while the subshells keep showing $x as value2 but $PS1 as '#'? Just in case, I'm trying this under OpenBSD.
[Yeah, I know... What on earth am I doing with OpenBSD if I don't know this? Just toying... in an isolated, most definitely non-production VM =).]
Because your subshells are sourcing something that's resetting PS1.
To debug this, try ksh -x
. If that doesn't help, you could try running ksh
in strace
or an equivalent system call tracing tool.
In case anybody is interested, somebody finally explained this in an OpenBSD mailing list. This behavior is actually expected in OpenBSD, as explained in a comment inside /usr/src/bin/ksh/main.c:
safe_prompt = ksheuid ? "$ " : "# ";
{
struct tbl *vp = global("PS1");
/* Set PS1 if it isn't set, or we are root and prompt doesn't
* contain a # or \$ (only in ksh mode).
*/
if (!(vp->flag & ISSET) ||
(!ksheuid && !strchr(str_val(vp), '#') &&
(Flag(FSH) || !strstr(str_val(vp), "\\$"))))
/* setstr can't fail here */
setstr(vp, safe_prompt, KSH_RETURN_ERROR);
}
Check the following files for rogue PS1 assignments.
/etc/profile
The system wide initialization file, executed for login shells.
$HOME/.profile
The personal initialization file, executed for login shells
after /etc/profile.
$HOME/..kshrc
Default personal initialization file, executed for interactive
shells when ENV is not set.
/etc/suid_profile
Alternative initialization file, executed when instead of per-
sonal initialization file when the real and effective user or
group id do not match.
There may be a typo in that manpage, it probably meant to say: $HOME/.kshrc
精彩评论