Skip to content

Instantly share code, notes, and snippets.

@SomajitDey
Last active September 26, 2021 16:11
Show Gist options
  • Save SomajitDey/33b9beda4b8acd6ccf3661e24857aec4 to your computer and use it in GitHub Desktop.
Save SomajitDey/33b9beda4b8acd6ccf3661e24857aec4 to your computer and use it in GitHub Desktop.
Bash and read -p prompts are sent to stderr...and more info
The readline prompt [read -p] is sent to stderr
The prompt for interactive bash is also sent to stderr. See POSIX mandate below
Source : https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
PS1 :: Each time an interactive shell is ready to read a command, the value of this
variable shall be subjected to parameter expansion and written to standard error.
NOTE (source- Bash reference manual):
1. Bash expands and displays PS1 before reading the first line of a command, and expands
and displays PS2 before reading the second and subsequent lines of a multi-line command.
Bash expands and displays PS0 after it reads a command but before executing it.
2. To see how a variable will look after expansion as prompt do: echo -e "${var@P}"
3. To have a certain command executed after each command finishes execution, set the
PROMPT_COMMAND environment variable in interactive bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment