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 Answer
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
>bar'
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
%bar'
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
orprintf
is needed to show escape characters correctly. Apr 16, 2015 at 15:09
"
(double quote) on the terminal and press Enter. As bash does not see the matching quote to close the string, it will showPS2
to complete the multiline command.