Skip to content

Instantly share code, notes, and snippets.

@mrnejc
Last active January 21, 2016 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrnejc/16217061c5b99615cf72 to your computer and use it in GitHub Desktop.
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
#!/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