So I'm trying to create a script to generate a random password with certain criteria, but for some reason some of my integer values aren't showing as such. Here is the script:
#!/bin/bash
PASSWORDLENGTH= shuf -i 8-16 -n 1
RNDSOURCE=/dev/urandom
L="acdefghjklmnopqrstuvwxyz"
U="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
N="012345679"
S='@#$%&*+-='
ALL="$L$U$N"
function rndindex() { echo $(($RANDOM % ${#1})); }
password="${L:$(rndindex $L):1}${U:$(rndindex $U):1}${N:$(rndindex $N):1}${S:$(rndindex $S):1}"
password=$password${ALL:$(rndindex $S):1}
while [ "${#password}" -lt "$PASSWORDLENGTH"" ] #Line 15
do
password=$password${ALL:$(rndindex $ALL):1}
done
chars=$password
password=""
while [ "${#password}" -lt "$PASSWORDLENGTH"" ] #Line 22
do
n=$(rndindex $chars)
ch=${chars:$n:1}
password="$password$ch"
if [ $n = $(( ${#chars} - 1 )) ]; then
chars="${chars:0:$n}"
elif [ $n = 0 ]; then
chars="${chars:1}"
else
chars="${chars:0:$n}${chars:$((n+1))}"
fi
done
echo $password
The error messages I'm getting are:
line 15: [: : integer expression expected
line 22: [: : integer expression expected