#! /bin/sh #!buildShellBin path=coreutils # # NAME # genpasswd - generate a password # # SYNOPSIS # genpasswd [OPTION]... # # DESCRIPTION # Produce a random string of a given length and alphabet to standard # output. # # --length=number (default: 71) # Specify the number of bytes to produce. # # --alphabet=string (default: -+.,=/A-Za-z0-9_) # Specify the list of characters that can be produced. # The string gets interpreted by tr and may contain single-character # collating elements. See tr(1) for details. # # --newline=bool (default: true) # Specify whether a newline should be appended to the output. # set -efu alphabet=-+.,=/A-Za-z0-9_ length=71 newline=true while test $# -gt 0; do case $1 in --alphabet=*) alphabet=${1//--alphabet=} shift ;; --length=*) length=${1//--length=} shift ;; --newline=true|--newline=false) newline=${1//--newline=} shift ;; *) echo "$0: bad argument: $1" >&2 exit 1 esac done tr -dc -- "$alphabet" < /dev/urandom | dd status=none bs="$length" count=1 case $newline in true) echo esac