Score:3

how to set bash environment variable based on bash command

pr flag

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.

hr flag
The second one looks OK to me - in what way exactly does it not work?
Alex avatar
pr flag
@steeldriver, bash simple freeze after second variant and waiting something, only ctrl-c allow to return command prompt
Tilman avatar
cn flag
Second version works for me. Perhaps your test was blocking because entropy was exhausted. Try /dev/urandom for comparison.
Alex avatar
pr flag
@Tilman, with /dev/urandom all working perfectly. I'm sorry, how to restore my entropy? Or this is not need? Can I working with /dev/urandom always in future?
Tilman avatar
cn flag
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.
Alex avatar
pr flag
Thank you, @Tilman. Post anser please, and I will mark it as solution.
bac0n avatar
cn flag
no need to redirect `<`, xxd takes infile as an argument.
Alex avatar
pr flag
@bac0n, thank you, cool.
Score:6
cn flag

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)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.