Created
June 15, 2017 07:23
-
-
Save ysakasin/8aba719926f5ba0b57b237cc4feea826 to your computer and use it in GitHub Desktop.
パスワード用にランダムな文字列を生成する
This file contains hidden or 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
| #!/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