I have the following shell script. The problem I am facing is that in the first iteration ${NUM[${i}]} returns the whole content of the array and every following iteration returns empty. Why is that so?
NUM="2 2 2 0"
i=0
for CLIENT in ${BAG_CLIENTS} ; do
if [ "$BFT" = true ]; then
SERVERS="-$i"
fi
echo "Starting ${NUM[${i}]} clients with $PERCWRITES writes and $SERVERS serv$
ssh rneiheiser@$CLIENT "~/runclient.sh $i ${NUM[${i}]} $PERCWRITES $SERVERS &$
((i++))
done
num=( 2 2 2 0 )sshmunges all its arguments together into a single string, and passes that string for execution by a remote shell. If you want to maintain control over how things are parsed by that remote shell, the proper practice is to build an singleeval-safe string locally and pass it as a single argument.$(rm -rf ~)inside that comment to be parsed by the remote shell as code).