3

根据man bash,在PS1环境变量中(定义shell提示符):

\[     begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\]     end a sequence of non-printing characters

根据我见过的各种例子,我应该用\[and包围非打印字符序列\]- 但我是否包含它们似乎没有任何区别!

例如:

export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n[\t]\$ '

似乎与以下工作没有什么不同:

export PS1='\e]0;\w\a\n\e[32m\u@\h \e[33m\w\e[0m\n[\t]$ '

(即相同但删除\[\]删除)。

那么以这种方式封闭非打印字符序列有什么好处呢?是否用于输出到哑终端(我永远不需要这样做),以便可以忽略非打印字符?(大概PS1在非交互式会话中被忽略,所以我猜它不能用于编写脚本。)

4

0 回答 0