PS2、PS3、PS4はどのような状況でプロンプトとして使用されますか?

PS2、PS3、PS4はどのような状況でプロンプトとして使用されますか?

シェルにログインすると、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ときに表示されるプロンプト、デバッグトレースラインプレフィックスです。selectPS4

私が引用した文書にはあまり記載されていませんが、 PS3bashのデフォルト値は次のとおりです#?

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

おすすめ記事