shell补-特殊玩法-color颜色实战
shell补-特殊玩法-color颜色实战
格式
echo -e "\e[1;31m红色字mygirl\E[0m"
\E 也可以用\033替代。开始结尾符号(大小写不区分)
[1数字1表示加粗显示(这个位置可以加不同的数字代表不同的意思,;eg1是加粗,5是blink闪烁.详细信息man console_codes 获得)
31m表示为红色字体,这个可以换不同的数字,代表不同的颜色“红色字mygirl”
0m表示关闭所有属性,这个位置可以换不同的数字,以代表不同的意思
set red foreground #foreground 前台颜色 字体颜色
set green background #background 背景颜色
[root@localhost ~]# echo -e "\e[1;31m红色字体mygril\e[0m"
红色字体mygril
[root@localhost ~]# echo -e "\e[1;32m绿色字体mygril\e[0m"
绿色字体mygril
#################经典案例
[root@localhost color]# cat testcolor.sh
#!/bin/bash
red="\e[1;31m"
green="\e[1;32m"
end="\e[0m"
login()
{
cat << EOFS
1.input [red|r] and your content set red foreground!
2.input [green|g] and your content set green foreground!
EOFS
}
input(){
read colors content
case "${colors}" in
"red"|"r")
echo -e "${red}${content}${end}"
;;
"green"|"g")
echo -e "${green}${content}${end}"
;;
*)
echo "you must inpuut {red|r|green|g}"
;;
esac
}
main(){
login
input
}
main
[root@localhost color]# bash testcolor.sh
1.input [red|r] and your content set red foreground!
2.input [green|g] and your content set green foreground!
r hai
hai ###该内容会显示红色
[root@localhost color]# bash testcolor.sh
1.input [red|r] and your content set red foreground!
2.input [green|g] and your content set green foreground!
g come
come ####会显示绿色
[root@localhost color]#
分类:
shell实战2查漏补缺
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!