I want to create a custom variable or command that can be called on like $RANDOM, but for strings. I have a script that creates a random string, using /dev/urandom . The script produces a randomly generated string each time the script is run.
#!/bin/bash
rando=$(head -100 /dev/urandom | tr -dc a-zA-Z0-9 | fold -w 15 | head -1)
echo $rando
If I create an alias or environmental variable that calls on the script, it will produce only one variation of a random string until a new bash sessions is created. How can I make it so it will create a new variation of the random string in the same bash session?
.bashrc. Then every time you call it, the code will run.$randois of course the same until you change it, but callingddetc again will create a new value each time. Or are you asking how to make a function around this code?RANDOMis a special built-in parameter; you can't define your own variable whose value changes every time you expand it.tr -dc a-zA-Z0-9 </dev/urandom | head -c 15