A #riddle. There are two pitfalls in this code. One cloaking the other. Can you see them?
#!/bin/bash
# generate a random string of length '$bytes' using characters from
# expression '$chars'
generate_random_string() {
local bytes=${1:-24}
local chars=${2:-'A-Za-z0-9'}
dd if=/dev/urandom bs=1 count=1111 2>/dev/null \
| tr --complement --delete "$chars" \
| sed --quiet 's/\(.\{'"$bytes"'\}\).*/\1/p'
}
# function generate_random_string is meant to be used in different
# scripts in contexts like:
# generating a random password
echo "password = '$(generate_random_string)'"
# generating a 64 byte seed base64 encoded
echo "seed = '$(generate_random_string 86 'a-zA-Z0-9/+')=='"