views:

45

answers:

1

Hello, I am trying to make a simple shell script to ping a source but I am getting

bash-2.03$ ./test.sh google.com 10 .5 /home/users/me 16 256
./test.sh: line 35: syntax error near unexpected token `(('
./test.sh: line 35: `for (( i = 1 ; i <= $totalArguments ; i++ ))'

This is the code:

#!/bin/bash

ip=$1
count=$2
interval=$3
outputDirectory=$4
shift;
shift;
shift;
shift;
totalArguments=$#

for (( i = 1 ; i <= $totalArguments ; i++ ))
do 
    ping -c $count -i $interval -s ${!i} $ip >> $outputDirectory/${!i}results.txt
done

Can someone tell me what I am doing wrong with the for loop syntax? Thanks!

+4  A: 

According to the CHANGES file, that style of for loop was added in Bash 2.04.

You will need to use seq:

for i in $(seq $totalArguments)
Dennis Williamson