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

I also encountered 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?

1 Answer 1


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
#? 2
#? ^C
  • 2
    perfect!!! what is the select command for ? Commented Mar 31, 2015 at 20:58
  • 18
    select is a bash way to do simple interactive menus, see ss64.com/bash/select.html for a more complete description.
    – dhag
    Commented Mar 31, 2015 at 21:00
  • @dhag, So it's like if else..?
    – Pacerier
    Commented Nov 2, 2017 at 13:41
  • 1
    @Pacerier more like for .. in but linux (at least bash) has that as well
    – Nate T
    Commented Jun 27, 2021 at 3:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .