bash - 如何让 bash shell 显示彩色文本?

标签 bash

这个问题在这里已经有了答案:





Get color output in bash

(5 个回答)


7年前关闭。




我看到有人可以在 bash shell 中制作输出以彩色显示。不仅突出显示错误或警告,还突出显示执行 'ls' 时的目录。

有谁可以告诉我怎么做吗?非常感谢。

最佳答案

您可以查看 thisthis :-

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/

相关文章:

linux - 你如何引用 Bash/Shell 脚本中的错误?

bash - 在文件列表中查找两个字符串并获取文件名

bash,比较命令的输出

bash - 使用 tee 命令创建时间特定的日志文件

bash - 复制(cp)符号链接(symbolic link)指向的东西而不是符号链接(symbolic link)本身

linux - BASH - 将包含二进制数的文本文件转换为二进制文件

linux - 无法通过 expect 对 bash 命令脚本进行 SSH

linux - 如何使用 diff (bash) 只显示不同的行

linux - 对于冒号前的字段与模式匹配的行,在冒号后提取字段

BASH - IP 地址中的远程前导零