简体   繁体   English

Shell脚本For循环语法错误

[英]Shell Scripting For loop Syntax Error

I am trying to make a simple shell script to ping a source but I am getting 我正在尝试制作一个简单的Shell脚本来ping源,但是我正在

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? 有人可以告诉我for循环语法在做什么吗? Thanks! 谢谢!

According to the CHANGES file, that style of for loop was added in Bash 2.04. 根据CHANGES文件,在Bash 2.04中添加了for循环样式。

You will need to use seq : 您将需要使用seq

for i in $(seq $totalArguments)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM