Array of all possible colors in bash script

Sometime back, we had looked at using colors in bash script and here is a way to create a array of all the colors.

#!/bin/bash - 
#===============================================================================
#
#          FILE:  colorarray.sh
# 
#         USAGE:  ./colorarray.sh 
# 
#   DESCRIPTION:  
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Amit Agarwal (aka), [email protected]
#       COMPANY: Roamware India Pvt Ltd
#       CREATED: 16/04/12 17:24:09 IST
# Last modified: Mon Apr 16, 2012  05:39PM
#      REVISION:  ---
#===============================================================================
count=0
for i in 40m 41m 42m 43m 44m 45m 46m 47m
do
    for l in 0 1
    do
        echo -n "l=$l "
        for k in 0 1
        do
            # echo -n "k=$k "
            for j in {30..37}
            do
                carr[$count]="\033[$k;$j;$l;$i"
                echo -ne "${carr[$count]}$count \033[00m"
                ((count++))
            done
        done
        echo
    done
    echo
done

You can add this script to any script of your choice and you have all the 256 colors available to you in the script without additional coding. Happy coding.

Enhanced by Zemanta