Last active
January 21, 2016 10:47
-
-
Save mrnejc/16217061c5b99615cf72 to your computer and use it in GitHub Desktop.
bash: generate random string of variable lengthdefault string length is 64 if not provided as 1st parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
V=$1 | |
if [ "$V" -eq "$V" ] 2>/dev/null | |
then | |
LEN=$1 | |
else | |
LEN=64 | |
fi | |
echo $(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $LEN | head -n 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment