Bash颜色变量输出 [英] Bash Color Variable Output

查看:102
本文介绍了Bash颜色变量输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量,让我们说 $ x ,它拥有 website.com 的值。我想能够调用这个变量,并应用shell颜色:

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?

推荐答案

您需要使用

You need to use " instead of '.

因此应该是: echo -e\ 033 [1; 32m $ x:\033 [0m;

变量通常在双引号内插入。

Variables are generally interpolated inside double quotes.

这篇关于Bash颜色变量输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆