The following script will generate 16 character length random string:
#!/usr/bin/env bash
password=""
while [ ${#password} -lt 16 ]; do
generated_str="$(dd if=/dev/random bs=1 count=32 2>/dev/null | tr -dc 'A-Za-z0-9!@#$%^&*()_+')"
password="$password$generated_str"
done;
echo -n "${password:0:16}"
It will concatenate and fill the string password
with pre-defined characters until the length is sufficient enough to be a standard password length, 16.
The concatenation comes into play to speed up the process, so it will be much faster than the other way around.
example usage (assuming the script was saved as a file with name genpwd
):
genpwd | xclip -sel clip