31

When I log on into the shell I see the prompt whose value is stored in PS1.

I also encountereded another prompt (but do not know which one) when I used the here-document syntax:

bc << HERE
>

But that is all the types of prompts. I have encountered so far. What kind of situations evoke the different kinds of prompts?

43

Here is what the bash documentation says:

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 ``+ ''.

So, PS1 is your normal "waiting for a command" prompt, PS2 is the continuation prompt that you saw after typing an incomplete command, PS3 is shown when the select command is waiting for input, and PS4 is the debugging trace line prefix.

The documentation I quoted doesn't say so, but the default for PS3 in bash is #?:

$ select x in foo bar baz; do echo $x; done
1) foo
2) bar
3) baz
#? 3
baz
#? 2
bar
#? ^C
  • 2
    perfect!!! what is the select command for ? – Abdul Al Hazred Mar 31 '15 at 20:58
  • 10
    select is a bash way to do simple interactive menus, see ss64.com/bash/select.html for a more complete description. – dhag Mar 31 '15 at 21:00
  • @dhag, So it's like if else..? – Pacerier Nov 2 '17 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.