Generate random passwords in shell with one special character Generate random passwords in shell with one special character unix unix

Generate random passwords in shell with one special character


#! /bin/bashchars='@#$%&_+='{ </dev/urandom LC_ALL=C grep -ao '[A-Za-z0-9]' \        | head -n$((RANDOM % 8 + 9))    echo ${chars:$((RANDOM % ${#chars})):1}   # Random special char.} \    | shuf \    | tr -d '\n'
  • LC_ALL=C prevents characters like ř from appearing.
  • grep -o outputs just the matching substring, i.e. a single character.
  • shuf shuffles the lines. I originally used sort -R, but it kept the same characters together (ff1@22MvbcAA).