Skip to content

Instantly share code, notes, and snippets.

@arosemena
Created October 22, 2015 17:48
Show Gist options
  • Save arosemena/d2cd8394d2e56adb0dbc to your computer and use it in GitHub Desktop.
Save arosemena/d2cd8394d2e56adb0dbc to your computer and use it in GitHub Desktop.
Generates a random password in bash, can be passed a parameter for length of said password, defaults to 30 characters if no parameter or if parameter isn't a number
case $1 in
''|*[!0-9]*) n=30 ;;
*) n=$1 ;;
esac
</dev/urandom tr -cd 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$@!' | head -c$n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment