问题
I've got a variable, let's say $x
and it holds the value of website.com
. I want to be able to call the variable and apply shell color to it like so:
echo -e '\033[1;32m$x:\033[0m';
The problem is not the color, however, it's how the script it interpretting the output. So the output I'm getting is:
$x:
I need the output to obviously be the string in the variable, and not the variable name. Is there any way around this issue?
回答1:
You need to use "
instead of '
.
So it should be: echo -e "\033[1;32m$x:\033[0m";
Variables are generally interpolated inside double quotes.
来源:https://stackoverflow.com/questions/2829276/bash-color-variable-output