Pradhvan Bisht Pradhvan Bisht - 1 year ago 121
Bash Question

Shell script to generate random hex numbers

I need some help in the shell script. Here is a code I am using to edit image filters where I am using hex colors along with white color. Now I need to make random hex color so that the code will generate a new image every time the code runs. I am able to do it by specific hex color codes.
Here is the code for that :

STRING="Freddy script converts an image into a different style"
echo $STRING

filename=(${arg//./ })

echo $filename

./freddy/popart -r 1 -c 1 -g 0 -i bilinear -c1 "#FF0000 white" $1 output-beta/$filename-popart1.png

In the above code popart is the image filter script and output-beta is the folder where the popart1.png will be saved. I need to make random hex codes in place of "#FF0000". Please help.

Answer Source
 echo "#$(openssl rand -hex 3)"

It has the benefit of being secure random.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download