I've been customizing my terminal prompt, and found that it's possible to change the "secondary prompt". However, I have no way to test the changes I make to this one so I was wondering if a simple script could be written to test the new $PS2?

  • 1
    Put " (double quote) on the terminal and press Enter. As bash does not see the matching quote to close the string, it will show PS2 to complete the multiline command.
    – 0x2b3bfa0
    Apr 16, 2015 at 15:04

1 Answer 1


From man bash:

   PS2    The value of this parameter is expanded as with PS1 and used  as
          the secondary prompt string.  The default is ``> ''.

The "secondary prompt string" is what is shown when you have multi-line input. For example:

$ echo 'foo

The > shown above is PS2. If I were to change that, I would see it as soon as I tried any multi-line command:

$ PS2="%"
$ echo 'foo

Ways to run multi-line commands include:

  • Open quotes (single or double) and hit enter without closing them.
  • Add a backslash to the end of a command and hit enter:

    $ echo foo \
  • Use a HEREDOC:

    $ echo <<<END  ## hit enter

As for doing it with a script, that's really not needed but you can simply write a script that prints PS2:

#!/usr/bin/env bash
printf "PS2 : %s\n" "$PS2"
  • Your script doesn't show colored prompts and mine does ;-) echo -e or printf is needed to show escape characters correctly.
    – 0x2b3bfa0
    Apr 16, 2015 at 15:09

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.