0

I have some code that doesn't work. It's says, "No such file or directory", and crashes on line 27:

while [ $i  < $amount]

But I don't know why. Anyone?

#!/bin/bash
#WWGEN Aleandro

small=$(echo "abcdefghijklmnopqrstuvwxyz")
big=$(echo "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
C=$(echo "\"")
D=$(echo '!')
E=$(echo ",.@#$%^&*()][{};:?-_+=")
F=$(echo "0123456789")

characters=$(echo $small$big$C$D$E$F)

while getopts ":cl:p:" opt; do
  case "$opt" in
    c) characters=$(echo $big$C$D$E$F);;
    l) length=$OPTARG ;;
    p) amount=$OPTARG ;;
  esac
done
shift $(( OPTIND - 1 ))

i=0

echo "amount: $amount"
echo "length: $length"

while [ $i  < $amount]

do

echo  "test"
echo $characters | sed 's/\(.\)/\1\n/g ' | sed 's/^$//g'| shuf -n $length | paste -sd ''

i=$[$i+1]

done

Output:

bash wwgen.sh -l 6 -p 5
amount: 5
length: 6
wwgen.sh: line 27: [: 0: binary operator expected

Wanted Output: 5 random generated passwords with length of 6 like this.

bash wwgen.sh -l 6 -p 5
amount: 5
length: 6
69:AY
O7H;=
64]Z
]^NL!
(&NW5
Aleandro
  • 43
  • 7

1 Answers1

1
while [ $i < $aantal ]

tries to do some stuff involving taking input from file $aantal which explains the message.

For inferior test use:

while [ $i -lt $aantal ]

Simple example to prove my point:

#!/bin/bash
i=0
a=2
while [ $i -lt $a ]
do
  i=$[i+1]
  echo $i
done

output:

1
2

However, if I don't define a I get:

./test.sh: ligne 3 : [: 0 : opérateur unaire attendu

(I'll let you perform the translation from french :))

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219