0

I have been trying to debug this loop for a while now (no pun intended!)

I wonder if anyone can tell me if I am missing something obvious

code below

echo enter number of occupants
read occupant_number
echo $occupant_number
i=0

while [$i -lt $occupant_number]
do
    echo "Enter occupant${i+1}'s name"
  read occupant${i+1}_name 
  echo "Enter occupant${i+1}'s MAC address"
  read occupant${i+1}_macaddress
  i=i+1
done

the console output is below:

 bash main.sh enter number of occupants 5 5 main.sh: line 7: [0: command not found


Line 7 is the line with the while [$i -lt $occupant_number]

Any help with getting this working is greatly appreciated guys! Thanks

  • 3
    The *syntax* is fine; you are just trying to execute a command named `[0` instead of a command named `[` due to the missing whitespace. Run your code through shellcheck.net – chepner May 18 '22 at 13:04
  • Many thanks @chepner that was the issue indeed! shellcheck.net is super useful! cheers – debaser_101 May 18 '22 at 18:29

0 Answers0