I have the following code:
</dev/urandom tr -dc 'A-Za-z0-9@#$%&_+=' | head -c 16
which is randomly generating passwords perfectly.
I want two changes:
- It should only contain one special character listed above
- It should choose a random length
I tried with length = $(($RANDOM%8+9))
then putting length as
</dev/urandom tr -dc 'A-Za-z0-9@#$%&_+=' | head -c$length
but got no positive result.
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 usedsort -R
, but it kept the same characters together (ff1@22MvbcAA
).