rgb2hexscript

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
williams2
Posts: 337
Joined: Fri 14 Dec 2018, 22:18

rgb2hexscript

#1 Post by williams2 »

There is a file rgb2hexscript in bionicpup64-8.0

It's possible to use awk to convert numbers to hex.
This should do the same thing as the sh script:

Code: Select all

echo $1 $2 $3 | awk '{printf "%02X%02X%02X\n",$1,$2,$3}'
This allows the script to be used with a pipe:

Code: Select all

#!/bin/ash
if test $# -eq 0
then
  awk '{printf "%02X%02X%02X\n",$1,$2,$3}'
else
  echo $1 $2 $3 | awk '{printf "%02X%02X%02X\n",$1,$2,$3}'
fi
Not a bug.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: rgb2hexscript

#2 Post by MochiMoppel »

williams2 wrote:It's possible to use awk to convert numbers to hex.
Possible, but why use awk?

Code: Select all

#!/bin/ash
R=255
G=120
B=10
printf "%02X%02X%02X\n" $R $G $B

Post Reply