I want to produce random string by command

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

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.

  • 3
    The second one looks OK to me - in what way exactly does it not work? Jan 22 at 21:41
  • 2
    Second version works for me. Perhaps your test was blocking because entropy was exhausted. Try /dev/urandom for comparison.
    – Tilman
    Jan 22 at 22:14
  • 1
    Entropy is collected continuously, you just have to wait. If you don't want to wait use /dev/urandom which for most purposes ist just as good.
    – Tilman
    Jan 22 at 22:32
  • 1
    Thank you, @Tilman. Post anser please, and I will mark it as solution.
    – Alex
    Jan 22 at 22:34
  • 1
    no need to redirect <, xxd takes infile as an argument.
    – bac0n
    Jan 23 at 7:37

1 Answer 1


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.