bash - 如何在 Bash 中输出粗体文本?

我正在编写一个在屏幕上打印一些文本的 Bash 脚本:

echo "Some Text"

我可以格式化文本吗?我想把它加粗。

最佳答案

最兼容的方式是使用 tput 来发现正确的序列发送到终端:

bold=$(tput bold)
normal=$(tput sgr0)

然后你可以使用变量 $bold$normal 来格式化:

echo "this is ${bold}bold${normal} but this isn't"

给予

this is bold but this isn't

https://stackoverflow.com/questions/2924697/

相关文章:

java - 如何在 Java 中打印带有 2 位小数的 float ?

ruby-on-rails - 在ruby中将 Camel 大小写转换为下划线大小写

formatting - 如何更改 Visual Studio Code 中的缩进?

java - 如何格式化带有前导零的Java字符串?

c# - 如何在 .NET 中使用自定义格式对 TimeSpan 对象进行 String.Forma

android - 在Android中设置TextView span的颜色

windows - 在 Windows 批处理脚本中格式化日期和时间

html - 从 XML 中的 html 格式的字符串资源设置 TextView 文本

c# - 自定义数字格式字符串以始终显示符号

c# - 如何使用 ToString() 格式化可为空的 DateTime?