Bash

PS2、PS3、PS4在哪些情況下用作提示?

  • April 7, 2020

當我登錄到 shell 時,我看到提示其值儲存在 PS1 中。

在使用 here-document 語法時,我還遇到了另一個提示(但不知道是哪一個):

bc << HERE
>

但這就是所有類型的提示。到目前為止我都遇到過。什麼樣的情況會引起不同類型的提示?

這是 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還是調試跟踪行前綴。

我引用的文件沒有這麼說,但是 PS3bash 中的預設值是#?

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

引用自:https://unix.stackexchange.com/questions/193659