Home:ALL Converter>How do I escape color codes in Bash?

How do I escape color codes in Bash?

Ask Time:2018-06-08T22:07:21         Author:Wilfred Hughes

Json Formatter

I have some color codes in my ~/.bashrc:

export LESS_TERMCAP_mb=$'\E[01;31m'       # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m'  # begin bold
export LESS_TERMCAP_me=$'\E[0m'           # end mode

This adds some color to my man pages. However, when I use env, bash still interprets the color codes:

$ env | grep LESS


env colors

How can I escape these strings so I can see them as string literals? Ideally something like env | escape_color_codes_somehow.

Author:Wilfred Hughes,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50762472/how-do-i-escape-color-codes-in-bash