`export PS1 ='value'`不会传播到(Korn)root的子shell?

时间:2011-01-02 22:19:42

标签: shell ksh

请考虑以下/root/.profile:

export PS1=value1
export x=value2

为什么登录shell显示预期的提示($ x为value2),而子shell继续显示$ x为value2但$ PS1为'#'?以防万一,我在OpenBSD下尝试这个。

[是的,我知道......如果我不知道这个,我在用OpenBSD做什么呢?只是玩弄...在一个孤立的,绝对非生产的VM =)。]

3 个答案:

答案 0 :(得分:3)

因为你的子弹正在寻找重置PS1的东西。

要调试此操作,请尝试ksh -x。如果这没有帮助,您可以尝试在strace or an equivalent系统调用跟踪工具中运行ksh

答案 1 :(得分:1)

检查以下文件是否存在恶意PS1分配。

   /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.

该联机帮助页可能存在拼写错误,可能意味着:$HOME/.kshrc

答案 2 :(得分:1)

如果有人感兴趣,有人最终解释了这个in an OpenBSD mailing list。在OpenBSD中实际上需要这种行为,如/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);
}