From 60941bc007506a367c7209f6fc961070dbc77360 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Tue, 6 Oct 2020 14:45:41 +0100 Subject: [PATCH] BIN: Adds hex2rgb script --- bin/.bin/conversion/hex2rgb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 bin/.bin/conversion/hex2rgb diff --git a/bin/.bin/conversion/hex2rgb b/bin/.bin/conversion/hex2rgb new file mode 100755 index 00000000..c85c8436 --- /dev/null +++ b/bin/.bin/conversion/hex2rgb @@ -0,0 +1,13 @@ +#!/bin/sh +# https://stackoverflow.com/questions/7253235/convert-hexadecimal-color-to-decimal-rgb-values-in-unix-shell-script/7253786#7253786 +hexinput="$(echo $1 | tr '[:lower:]' '[:upper:]')" # uppercase-ing +a=`echo $hexinput | cut -c-2` +b=`echo $hexinput | cut -c3-4` +c=`echo $hexinput | cut -c5-6` + +r=`echo "ibase=16; $a" | bc` +g=`echo "ibase=16; $b" | bc` +b=`echo "ibase=16; $c" | bc` + +echo $r $g $b +exit 0