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