在什么情况下使用PS2,PS3,PS4作为提示?


31

当我登录到外壳程序时,我看到提示,其值存储在PS1中。

使用here-document语法时,我还遇到了另一个提示(但不知道是哪个提示):

bc << HERE
>

但这就是所有提示类型。到目前为止,我已经遇到了。哪种情况会引起不同的提示?

Answers:


43

这是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 mul
       tiple times, as necessary, to indicate multiple levels of  indi
       rection.  The default is ``+ ''.

因此,PS1是正常的“等待命令”提示,PS2是键入不完整命令后看到的继续提示, PS3select命令等待输入时显示,并且 PS4是调试跟踪行前缀。

我引用的文档没有这么说,但是PS3bash中的默认值 是#?

$ select x in foo bar baz; do echo $x; done
1) foo
2) bar
3) baz
#? 3
baz
#? 2
bar
#? ^C

2
完善!!!选择命令是做什么用的?
Abdul Al Hazred

10
select是执行简单交互式菜单的一种bash方式,请参见ss64.com/bash/select.html,以获取更完整的说明。
dhag 2015年

@dhag,所以像if else..吗?
Pacerier's
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.