How to Set Bash Environment Variable Based on Bash Command

How to Set Bash Environment Variable Based on Bash Command

I want to produce random string by command

 xxd -l 32 -c 32 -p < /dev/random
 dd1ad9f2deae0af5412e82fbbeb2df6b239e91d49d98638cc5b4bb94aac25463

How to set environment variable? Both way below don't wotking

export TMP_RPC_PASS=$(echo xxd -l 32 -c 32 -p < /dev/random)
export TMP_RPC_PASS=$(xxd -l 32 -c 32 -p < /dev/random)

bash simple freeze after second variant and waiting something, only ctrl-c allow to return command prompt.

8

1 Answer

The second version works fine. The reason it appears to freeze is that /dev/random blocks when the system's entropy pool is exhausted, waiting for new entropy to be collected.

To avoid blocking, use /dev/urandom instead of /dev/random. For most purposes this is just as good.

export TMP_RPC_PASS=$(xxd -l 32 -c 32 -p /dev/urandom)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.