13

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

arg=$1
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.

2
  • What is the number of digits you want it to be? fixed ? do you want it to start from a certain number? Commented Oct 27, 2016 at 6:55
  • The number of digits must be 6 and It can start from #000000 Commented Oct 27, 2016 at 7:00

2 Answers 2

28
 echo "#$(openssl rand -hex 3)"

It has the benefit of being secure random.

Sign up to request clarification or add additional context in comments.

Comments

4

You can use the hexdump command to generate random three-byte hex codes like so:

hexdump -n 3 -v -e '"#" 3/1 "%02X" "\n"' /dev/urandom

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.