Bash 通过配置PS1在提示符上显示当前时间

Bash 通过配置PS1在提示符上显示当前时间,bash,Bash,我正在尝试配置PS1以显示当前时间,这是我的当前变量 me@host:~/Downloads$ env | grep -i 'ps1' PS1=\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ 计划的结果是 me@host; 09:00 AM: ~/Downloads$ \T以12小时格式扩展为当前时间

我正在尝试配置
PS1
以显示当前时间,这是我的当前变量

me@host:~/Downloads$ env | grep -i 'ps1'
PS1=\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ 
计划的结果是

me@host; 09:00 AM: ~/Downloads$
\T以12小时格式扩展为当前时间

临时配置它

me@host:~/Downloads$ export PS1="\[\e]0;\u@\h;\T: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$"
不幸的是,提示没有改变

我的用法有什么问题

  • 如果您使用双引号,那么变量扩展将去掉
    debian\u chroot
    部分
  • 字符串中嵌入了两个设置,但您只设置了一个:
    • 第一个(已更改)设置终端窗口的标题
    • 第二个(您没有更改)设置命令提示符
  • 尝试以下方法:

    PS1='\[\e]0;\u@\h;\T: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\];\T:\[\033[01;34m\]\w\[\033[00m\]\$ '