#!/bin/sh . ./colors.sh # $1 is the combined value # $2 is R, G or B extract() { case "$2" in R) awk "BEGIN{print substr(\"$1\", 1, 2)}" ;; G) awk "BEGIN{print substr(\"$1\", 3, 2)}" ;; B) awk "BEGIN{print substr(\"$1\", 5, 2)}" ;; *) return 1 ;; esac } # hex 2 decimal # $1 is a number in hex h2d() { printf '%d' 0x"$1" } # $1: color value # prints r,g,b rgb() { _rgb_r=$(h2d $(extract $1 R)) _rgb_g=$(h2d $(extract $1 G)) _rgb_b=$(h2d $(extract $1 B)) echo $_rgb_r,$_rgb_g,$_rgb_b } cat <