bin/.local/bin/rand (view raw)
1#!/bin/sh
2
3# rand (inspired by https://rgz.ee/random.html)
4#
5# generate random string from charset as first argument and length as second
6#
7# example:
8# $ rand '1-9a-f' 10
9# > 329402aa42
10#
11# defaults:
12# charset -- all printable characters and space
13# length -- 25
14
15[ -z $1 ] && charset=' -~' || charset=$1
16[ -z $2 ] && length=25 || length=$2
17
18tr -cd "$charset" < /dev/urandom | fold -w "$length" | head -n 1