I'm having a small problem with this following snippet and I'm not sure why. The error given is (line indicated):
*2: syntax error: operand expected (error token is "*2")
while [[ $numberServers -gt $newindex ]]; do
serverPort=$((9001+$(($newindex*2)))) <--- This line
clientPort=$(($serverPort+1))
newindex=$(($newindex+1))
localhostport=$((serverPort-2))
string=$(($string,localhost:$(($serverPort-2))))
...
Any help would be greatly appreciated.
$newindexdidn't have the value you were expecting. What value does it have?$newindexis empty. You should probably test that it has a value before you use it in a formula. Also, too many parentheses!serverPort=$((9001+$newindex*2))should do exactly the same thing. Similarly,newindex=$(($newindex+1))can be replaced with((newindex++)).localhost:$(($serverPort-2))to the end ofstring.string="$string,localhost:$localhostport"orstring+=",locahost:$localhostport". At best,$(($string,localhost:$locahostport))would evaluate$string, discard the result, and evaluate to the next string. But arithmetic expressions are for just that: arithmetic, not string handling. Neither argument of the,operator is an arithmetic expression.