Skip to content

Instantly share code, notes, and snippets.

@vvasabi
Last active December 31, 2015 16:36
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 vvasabi/2ce892cd2fe3026f81fd to your computer and use it in GitHub Desktop.
Save vvasabi/2ce892cd2fe3026f81fd to your computer and use it in GitHub Desktop.
A bash script that generates a random password and copies it to pastebook.
#!/bin/bash
LENGTH=16
if [ "$#" -gt 0 ]; then
LENGTH="$1"
fi
# from: https://gist.github.com/earthgecko/3089509
RESULT=`cat /dev/urandom \
| LC_CTYPE=C tr -dc 'a-zA-Z0-9-.?~!@#$%^&*' \
| head -c "$LENGTH"`
# comment out this line if you are not using Mac OS X
echo -n "$RESULT" | pbcopy
echo "$RESULT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment