You above script will return an output command like this
ssh root@host1 host2 script.sh
Here host2 is considered as an argument or a command which the shell is not able to recognize and hence you are getting the above error.
Assuming your use case is to run the shell script on both hosts the following script might help you
IFS=', ' read -r -a array <<< host1,host2
for host in ${array[@]}; do ssh root@$host script.sh; done
output command will be similar to below
ssh root@host1 script.sh
ssh root@host2 script.sh
for host in {host1,host2}IFSisn't doing what you think it is. Splitting happens on variable expansion, so it doesn't expand the literal value in theforstatement, but it does split the when the$hostvariable is expanded; essentially, it runsssh root@host1 host2 script.sh. This tries to runhost2as a command on host1. Moral: splitting withIFSis hard to understand and you're generally better off using other methods to get things done (like arrays).,delimiter.