当我登录到 shell 时,我看到提示符,其值存储在 PS1 中。
我在使用here-document语法时还遇到了另一个提示(但不知道是哪一个):
bc << HERE
>
但这就是所有类型的提示。目前为止我也遇到过。什么样的情况会引发不同类型的提示?
答案1
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
是输入不完整命令后看到的继续提示符, 是命令等待输入
PS3
时显示的提示符,是调试跟踪行前缀。select
PS4
我引用的文档没有这么说,但
PS3
bash 中的默认值是#?
:
$ select x in foo bar baz; do echo $x; done
1) foo
2) bar
3) baz
#? 3
baz
#? 2
bar
#? ^C