Given the following:
text="The quick $color fox jumps over the $adjective dog"
How can I echo $text with $color and $adjective values being colored in bash, but not changing the variable?
Example:
$ echo -e --highlight-variables $text
The quick \e[00;31mbrown\e[00m fox jumps over the \e[00;31mlazy\e[00m dog
(except with the actual colors)
But then:
$ echo -e $text
The quick brown fox jumps over the lazy dog
would have no color changes.
I want to be able to output the text with less so the user can review it in the console, but then write the variables to a file, but the file should not have the color info in it. The actual code I’m executing looks something like:
echo -e $text | less
echo "Is this acceptable?"
read accept
if [ "$accept" == "y" ]
then
echo -e $text > output.txt
fi
If I wrap the variables in color, the escaped text gets put in the file.
You just need to remove ansi sequences before you print.