【问题标题】:PS1 does not echo backslashPS1 不回显反斜杠
【发布时间】:2019-04-18 09:46:46
【问题描述】:

我想要这个 Bash 提示:

/\ /\
root@debian$:

我愿意:

PS1="/\  /\\n${debian_chroot:+($debian_chroot)}\u@\h\$:"

或者:

PS1="/\  /\\\n${debian_chroot:+($debian_chroot)}\u@\h\$:"

但我有:

/\  /
root@debian$:

【问题讨论】:

    标签: bash ps1


    【解决方案1】:

    PS1 本身做了一层额外的解释:

    PS1="/\  /\\\\\n${debian_chroot:+($debian_chroot)}\u@\h\$:"
              ^^^^ 4 backslashes
    

    或者更好:

    PS1="/\\\\  /\\\\\n${debian_chroot:+($debian_chroot)}\u@\h\$:"
    

    我得到的输出:

    /\  /\
    ibug@ubuntu$:
    

    专业提示:使用单引号来节省自己相当多的转义:

    PS1='/\\  /\\\n'"${debian_chroot:+($debian_chroot)}"'\u@\h\$:'
        ^          ^^                                  ^^        ^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-07
      • 2010-12-14
      • 1970-01-01
      • 2013-11-14
      相关资源
      最近更新 更多