控制輸出顏色的shell腳本
實(shí)現(xiàn)代碼:
#!/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" }
先定義函數(shù),接著初始化下函數(shù),接著你就可以看到效果了。
執(zhí)行
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
你了解了后以后及可以寫出帶顏色,很炫的腳本了
相關(guān)文章
linux命令行bandit使用練習(xí)實(shí)戰(zhàn)
這篇文章主要為大家介紹了linux命令行bandit使用練習(xí)實(shí)戰(zhàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08linux whatis與whatis database 使用及查詢方法(man使用實(shí)例)
在學(xué)習(xí)man命令時(shí)候,估計(jì)很多朋友都發(fā)現(xiàn)有man –f ,man –k 參數(shù),可以查出很多數(shù)據(jù)。這些有的與man手冊(cè)頁(yè)相同,有些不是屬于手冊(cè)頁(yè)的。它們數(shù)據(jù)怎么收集來的,并且whatis是怎么樣工作的2015-10-10使用shell腳本執(zhí)行hive、sqoop命令的方法
今天小編就為大家分享一篇使用shell腳本執(zhí)行hive、sqoop命令的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-06-06Linux?shell中$(())、$()、``與${}的區(qū)別
本文主要介紹了Linux?shell中$(())、$()、``與${}的區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06Linux 進(jìn)程替換(exec函數(shù))實(shí)現(xiàn)代碼
這篇文章主要介紹了Linux 進(jìn)程替換(exec函數(shù))實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-05-05Shell腳本中使用getopts處理多命令行選項(xiàng)
今天小編就為大家分享一篇關(guān)于Shell腳本中使用getopts處理多命令行選項(xiàng),小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-03-03linux命令學(xué)習(xí)之10個(gè)網(wǎng)絡(luò)命令和監(jiān)控命令
下面列出來的10個(gè)基礎(chǔ)的每個(gè)linux用戶都應(yīng)該知道的網(wǎng)絡(luò)和監(jiān)控命令,大家參考使用吧2014-01-01