mkpasswd: Add flags for charset/length - scripts - various script and utils
HTML git clone git://z3bra.org/scripts
DIR Log
DIR Files
DIR Refs
---
DIR commit ad357d6bf774f8fe765ecdf9162d81eed89bcf09
DIR parent 891f33f08486c513933e258dcba2ffbc62951448
HTML Author: Willy Goiffon <dev@z3bra.org>
Date: Thu, 20 Aug 2026 22:08:21 +0000
mkpasswd: Add flags for charset/length
Diffstat:
M mkpasswd | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
---
DIR diff --git a/mkpasswd b/mkpasswd
@@ -1,5 +1,20 @@
#!/bin/sh
-LEN=${1:-16}
+len=16
+chars='a-zA-Z0-9*#!%@:;/&_'
-</dev/urandom tr -cd ${CHAR:-'a-zA-Z0-9'} | fold -w ${LEN} | sed 1q
-\ No newline at end of file
+usage() {
+ echo "usage: $(basename $0) [-c chars] [-l len]" >&2
+}
+
+while getopts "c:l:h" OPT; do
+ case $OPT in
+ c) chars="$OPTARG" ;;
+ l) len="$OPTARG" ;;
+ h) usage; exit 0 ;;
+ *) usage; exit 1 ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+</dev/urandom tr -cd "$chars"|fold -w ${1:-$len}|sed 1q