I have this code:
# GENERATE RANDOM PASSWORD
# $1 = number of characters; defaults to 32
# $2 = include special characters; 1 = yes, 0 = no; defaults to 1
function randpass() {
[ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-32}
echo
}
randpass
randpass 10
randpass 20 0
SSHKEYPASS = randpass 10
I want to be able to generate a random password and store it as a variable. However, although randpass works just fine, when I try and set ```SSHKEYPASS`` to the result of randpass it doesn't work. So, how can I use my randpass function to generate a random password on the SSHKEYPASS variable.
Thank you.