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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like