MIAOU-BASH is a collection of settings and helpers for leveraging BASH. Developer-friendly, it may be used as solo package with or without the miaou project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
295 B

8 months ago
8 months ago
8 months ago
  1. #!/bin/bash
  2. SIZE=${1:-12}
  3. re='^[0-9]+$'
  4. if ! [[ $SIZE =~ $re ]]; then
  5. echo "error: SIZE=$SIZE Not a number" >&2
  6. exit 1
  7. fi
  8. if [[ $SIZE -lt 4 || $SIZE -gt 20 ]]; then
  9. echo "expected SIZE=$SIZE not in range [4..20]" >&2
  10. exit 1
  11. fi
  12. tr -cd '[:alnum:]' </dev/urandom | fold -w "$SIZE" | head -n1