3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

シェルで使える色一覧を確認するスクリプト

Last updated at Posted at 2017-01-23

シェルで使用できる色の一覧を表示するスクリプト。LS_COLORとかの参考用。

colors.sh
#!/bin/bash

# reference: man console_codes

for i in `seq 30 38` `seq 40 47` ; do
    for j in 0 1 2 4 5 7 ; do
        printf "\033[${j};${i}m"
        printf "${j};${i}"
        printf "\033[0;39;49m"  # set default
        printf " "
    done
    printf "\n"
done

実行結果

color_codes.png

ESC, [, パラメータ, mの順番で標準出力に制御コードを出力すれば色を変更できる。パラメータを複数指定する場合は;で区切る。デフォルトの色に戻す場合はパラメータを0;39;49とすればよい。
ESCを出力する場合はprintfコマンドでエスケープシーケンスを使い\033を表示する。

制御コードの詳細はman console_codesで確認できる。

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?