小编给大家分享一下如何实现控制输出颜色的shell脚本,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
实现代码:
#!/bin/sh # ANSI Color -- Use these variables to make output in different colors # and formats. Color names that end with 'f' are foreground (text) colors, # and those ending with 'b' are background colors. initializeANSI() { esc="\033" # if this doesn't work, enter an ESC directly blackf="${esc}[30m"; redf="${esc}[31m"; greenf="${esc}[32m" yellowf="${esc}[33m" bluef="${esc}[34m"; purplef="${esc}[35m" cyanf="${esc}[36m"; whitef="${esc}[37m" blackb="${esc}[40m"; redb="${esc}[41m"; greenb="${esc}[42m" yellowb="${esc}[43m" blueb="${esc}[44m"; purpleb="${esc}[45m" cyanb="${esc}[46m"; whiteb="${esc}[47m" boldon="${esc}[1m"; boldoff="${esc}[22m" italicson="${esc}[3m"; italicsoff="${esc}[23m" ulon="${esc}[4m"; uloff="${esc}[24m" invon="${esc}[7m"; invoff="${esc}[27m" reset="${esc}[0m" }
先定义函数,接着初始化下函数,接着你就可以看到效果了。
执行
echo -e ${yellowf}This is a phrase in yellow${redb} and red${reset}
echo -e ${boldon}This is bold${ulon} this is italics${reset} bye bye
echo -e ${italicson}This is italics${italicsoff} and this is not
以上是“如何实现控制输出颜色的shell脚本”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。