I have looked at the question How to count number of words from String using shell on SO, which explains how to count words inside a variable.
But this only counts one word inside my variable so I have no idea how to fix it.
I have the following variables:
vmfarm1=(host1.com host2.com host3.com host4.com ) maximus=(host11.com host 12.com host 13.com) firefly=(host5.com)
I need to find a way to count all the host names into a number inside the variables.
After this, the number inside that was counted, have to be used as a variable in this line.
I have tried:
echo "$input" | wc -w printf ' \n|/4.vmfarm1 ' >> textfile.txt
I have to write the
4 above by myself to the number and I need it to be done automatically, this is why I need a variable.