Why is something for $PS3 shown, even when $PS3 is empty?

Because the doc says so:

https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#Bash-Variables

PS3

The value of this variable is used as the prompt for the select command. If this variable is not set, the select command prompts with ‘#? ’


It seems to be hard-coded in Bash . In execute_cmd.c, function execute_select_command(), there's this:

ps3_prompt = get_string_value ("PS3");
if (ps3_prompt == 0)
    ps3_prompt = "#? ";

Note that it only happens if PS3 is unset. If you set it to an empty string, select will happily prompt you with, well, nothing.


In bash, PS3 was set to "#? " when not set, which is default.

Also, neither select nor PS3 is POSIX defined, so the behavior can be varied:

  • ksh, mksh, yash, zsh and schily sh set default to "#? ".
  • dash, heirloom sh, busybox sh do not set PS3

Tags:

Bash

Prompt