The command [
can't handle arithmetics inside its test. Change it to:
if [ $i -ne $((hosts_count-1)) ]; then
Edit: what @cebewee wrote is also true; you must put a space in front of the closing ]
. But, just doing that will result in yet another error: extra argument '-'