Read Command : Display the prompt in color (or enable interpretation of backslash escapes)

read won’t process any special escapes in the argument to -p, so you need to specify them literally. bash‘s ANSI-quoted strings are useful for this:

read -p $'\e[31mFoobar\e[0m: ' foo

You should also be able to type a literal escape character with Controlv Escape, which will show up as ^[ in the terminal:

read -p '^[[31mFoobar^[[0m: ' foo

Leave a Comment