-
-
Save nickolasburr/a49073af159254f784c17673619b99c0 to your computer and use it in GitHub Desktop.
Generate pseudo-random string of n characters.
This file contains 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
#!/usr/bin/env bash | |
### | |
### prsg: Generate pseudo-random string of n characters. | |
### | |
if [[ $# -eq 0 ]]; then | |
printf 'Usage: prsg LENGTH\n' | |
exit 1 | |
fi | |
LENGTH="$1" | |
REGEX='^[0-9]+$' | |
if ! [[ $LENGTH =~ $REGEX ]]; then | |
printf 'Argument must be an integer\n\nUsage: prsg LENGTH\n' | |
exit 1 | |
fi | |
LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c $LENGTH | xargs ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment