The command [ cannot process arithmetic 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 before closing ] . But only this will lead to another error: extra argument '-'
source share