我知道可以定制提示符(详见“6.9控制及时手册”中的Bash部分),我已经做了一段时间了,但最近我注意到了一些奇怪的行为。
考虑以下两种情况:
PS1='\$ '
PS2='> '
PS3='#? '
PS4='+ '
带转义序列的
PS1='\[\e[1;34m\]\$\[\e[0m\] '
PS2='\[\e[1;34m\]>\[\e[0m\] '
PS3='\[\e[1;34m\]#?\[\e[0m\] '
PS4='\[\e[1;34m\]+\[\e[0m\] '
因此,问题是:
PS3按原样打印,而不解释转义序列。PS4甚至没有打印出来。我很肯定他们以前曾经工作过,但由于我不经常使用,所以我不知道他们什么时候行为不端。
发布于 2018-04-23 16:01:48
来自man bash:
PS1 The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is ``\s-\v\$ ''.
PS2 The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is ``> ''.
PS3 The value of this parameter is used as the prompt for the select command (see SHELL GRAMMAR above).
PS4 The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The因此,无论出于何种原因,PS3的不扩展都是记录在案的行为。
至于PS4,您需要导出变量以使其在新的bash调用中可用。而且您需要显式地设置跟踪选项,-v不会打开它:
pse@Mithos:~/.tmp$ export PS4='uuuu: '
pse@Mithos:~/.tmp$ bash -c "set -x; echo foo"
uuuu: echo foo
foo发布于 2018-04-23 16:01:56
来自bash手册:
PS1 The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default
value is ``\s-\v\$ ''.
PS2 The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is ``>
''.
PS3 The value of this parameter is used as the prompt for the select command (see SHELL GRAMMAR above).
PS4 The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays
during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate
multiple levels of indirection. The default is ``+ ''.PS3的定义没有说明它是以与其他提示符字符串相同的方式展开的。您看到的行为与文档一致。
https://unix.stackexchange.com/questions/439513
复制相似问题