0

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!

2
  • the for loop syntax looks fine. Commented Jun 8, 2010 at 17:31
  • Script works as is for me on bash version 3.2.49. Commented Jun 8, 2010 at 17:34

1 Answer 1

5

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.