Bash Color Variable Output

倾然丶 夕夏残阳落幕 提交于 2020-01-14 02:45:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!