Skip to content

Instantly share code, notes, and snippets.

@ericcholis
Created April 14, 2015 12:16
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 ericcholis/b4cf2f628208368ab793 to your computer and use it in GitHub Desktop.
Save ericcholis/b4cf2f628208368ab793 to your computer and use it in GitHub Desktop.
Random String Generator
#!/usr/bin/env bash
usage()
{
cat << EOF
usage: random-string
This script run the test1 or test2 over a machine.
OPTIONS:
-h Show this message
-c Number of characters returned
-s Number of random strings returned
EOF
}
characters=32
strings=1
while getopts “hc:s:” OPTION
do
case $OPTION in
h)
usage
exit 1
;;
c)
characters=$OPTARG
;;
s)
strings=$OPTARG
;;
esac
done
i=1
echo ""
echo "Random Strings:"
echo "--------------------------------------"
while [[ $i -le $strings ]]
do
LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c $characters | xargs
((i = i + 1))
done
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment