控制輸出顏色的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下統(tǒng)計(jì)當(dāng)前文件夾下的文件個(gè)數(shù)、目錄個(gè)數(shù)
這篇文章主要介紹了Linux下統(tǒng)計(jì)當(dāng)前文件夾下的文件個(gè)數(shù)、目錄個(gè)數(shù),本文使用ls命令配合管理、grep命令實(shí)現(xiàn)統(tǒng)計(jì)需求,需要的朋友可以參考下2014-10-10
Debian 終端Shell命令行長(zhǎng)路徑改為短路徑的步驟
要將Debian終端Shell的命令行長(zhǎng)路徑更改為較短路徑,可以按照以下步驟進(jìn)行操作,本文給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2023-12-12
一天一個(gè)shell命令 文本操作系列-linux dd使用教程
dd 是 Linux/UNIX 下的一個(gè)非常有用的命令,作用是用指定大小的塊拷貝一個(gè)文件,并在拷貝的同時(shí)進(jìn)行指定的轉(zhuǎn)換2016-05-05

