Skip to content

Instantly share code, notes, and snippets.

@ysakasin
Created June 15, 2017 07:23
Show Gist options
  • Select an option

  • Save ysakasin/8aba719926f5ba0b57b237cc4feea826 to your computer and use it in GitHub Desktop.

Select an option

Save ysakasin/8aba719926f5ba0b57b237cc4feea826 to your computer and use it in GitHub Desktop.
パスワード用にランダムな文字列を生成する
#!/bin/bash
print_help () {
echo -e "Usage: mkpasswd [options] " 1>&2
echo -e " -l\tset password length" 1>&2
echo -e " -n\tset number of passwords" 1>&2
echo -e " -h\tshow this message" 1>&2
}
while getopts n:l:h OPT
do
case $OPT in
"n" ) NUM="$OPTARG" ;;
"l" ) LENGTH="$OPTARG" ;;
"h" ) print_help ; exit 1 ;;
* ) print_help ; exit 1 ;;
esac
done
cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w ${LENGTH:-16} | head -n ${NUM:-1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment