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

后端 未结 4 2039
星月不相逢
星月不相逢 2020-12-09 02:33

I often use something like read -e -p \"> All good ? (y/n)\" -n 1 confirm; to ask a confirm to the user.

I\'m looking for a way to colorize the outpu

4条回答
  •  星月不相逢
    2020-12-09 03:16

    I have another solution that allows you to use variables to change the text's format. I echo -e the the output I want into the -p argument of the read command.

    Here's an example:

    RESET="\033[0m"
    BOLD="\033[1m"
    YELLOW="\033[38;5;11m"
    read -p "$(echo -e $BOLD$YELLOW"foo bar "$RESET)" INPUT_VARIABLE
    

提交回复
热议问题