china0396 发表于 2026-6-6 15:59:14

在shell脚本里显示带颜色的字(linux)

一、echo命令(带参数-e)cat color.sh#!/bin/bashecho -e "\033echo -e "\033echo -e "\033echo -e "\033echo -e "\033echo -e "\033echo -e "\033echo -e "\033
二、printf命令cat color2.sh#!/bin/bashprintf "\033printf "\033printf "\033printf "\033printf "\033printf "\033printf "\033printf "\033
三、使用变量cat color3.sh#!/bin/bashblackcolor='\Eredcolor='\Egreencolor='\Eyellowcolor='\Ebluecolor='\Epurplecolor='\Ecyancolor='\Ewhitecolor='\Eecho -e "${blackcolor}black"echo -e "${redcolor}red"echo -e "${greencolor}green"echo -e "${yellowcolor}yellow"echo -e "${bluecolor}blue"echo -e "${purplecolor}purple"echo -e "${cyancolor}cyan"echo -e "${whitecolor}white"
页: [1]
查看完整版本: 在shell脚本里显示带颜色的字(linux)