这个问题在这里已经有了答案:
Get color output in bash
(5 个回答)
7年前关闭。
我看到有人可以在 bash shell 中制作输出以彩色显示。不仅突出显示错误或警告,还突出显示执行 'ls' 时的目录。
有谁可以告诉我怎么做吗?非常感谢。
最佳答案
Use ANSI escape sequences to set text properties like foreground and background colors.
示例:-
echo -e "\e[1;34mThis is a blue text.\e[0m"
和
#!/bin/bash
# tputcolors
echo
echo -e "$(tput bold) reg bld und tput-command-colors$(tput sgr0)"
for i in $(seq 1 7); do
echo " $(tput setaf $i)Text$(tput sgr0) $(tput bold)$(tput setaf $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setaf $i)Text$(tput sgr0) \$(tput setaf $i)"
done
echo ' Bold $(tput bold)'
echo ' Underline $(tput sgr 0 1)'
echo ' Reset $(tput sgr0)'
echo
关于bash - 如何让 bash shell 显示彩色文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18560647/