ANSI Escape CodeにおけるSGRコードを出力する。
成果物
詳しくは以下参照。
概要
\e[38;5;1m
で文字色を赤にする。このうち1
のSGRコード部分のみ出力する。
\e[38;5;1;48;5;2;58;5;4m
で文字色=赤、背景色=緑、下線色=青にする。このうち38;5;1;48;5;2;58;5;4
のSGRコード部分のみ出力する。
例
色はIndex Color番号0
〜255
の整数値を指定する。それぞれ位置引数ごとに文字色、背景色、下線色を指定する。
color8.sh 255 0 127
3bitカラーなら名前か特定の1字で指定できる。
color8.sh r g b
color8.sh red green blue
文字色=赤、背景色=緑、下線色=青にする。
COLOR="$(color8.sh r g b)" echo -e "\e[4;${COLOR}mここの色を変える\e[m"
文字色を指定したいなら-f
(fore
)、背景色を指定したいなら-b
(back
)、下線色を指定したいなら-l
(line
)オプションを使う。
color3.sh -f red color3.sh -b green color3.sh -l blue
3bitカラー名で-F
,-B
,-L
なら高輝度にする。
color3.sh -F red color3.sh -B green color3.sh -L blue
おまけ
- color8gray.sh
- color8safe.sh
8bitカラーはIndex Colorである。このうちグレイスケールを24段階で指定できたり、セーフカラー216色をRGB形式で指定できる。
color8gray.sh 23 0 12 color8gray.sh -f 23 -b 0 -l 12
color8safe.sh 5,0,0 0,5,0 0,0,5 color8safe.sh -f 5,0,0 -b 0 0,5 -l 0,0,5
対象環境
- Raspbierry pi 4 Model B
- Raspberry Pi OS buster 10.0 2020-08-20 ※
- bash 5.0.3(1)-release
$ uname -a Linux raspberrypi 5.4.83-v7l+ #1379 SMP Mon Dec 14 13:11:54 GMT 2020 armv7l GNU/Linux