0

Im trying to run this code . Basically I want the https://admin:qwerty123@'"$dmp"':7777/set_param?'"$params command to run 3 times for every ip in array. But Im getting errors like

prog.sh: line 7: syntax error near unexpected token `while'
prog.sh: line 7: `while [ $n -lt 3 ]; do'

Please can someone correct the code

#!/bin/bash 

n="0"
dmps=(10.104.164.104 10.35.176.77 10.35.176.126) # *****  put your dmp ips here *******

for dmp in ${dmps[@]}; 
while [ $n -lt 3 ]; do


  do res=$(curl -k -s --url 'https://admin:qwerty123@'"$dmp"':7777/set_param?'"$params"); 
  echo "DMP: $dmp - $res"; 
n=$[n+1]
done

done

1 Answer 1

4
  • add space before [
  • add ; do after ]

    while [ n -lt 3 ]; do
    

read more

Sign up to request clarification or add additional context in comments.

3 Comments

hi kev, actually I edited the code in original post. That is what I wanted. BUt In that Im getting error like prog.sh: line 7: syntax error near unexpected token while' prog.sh: line 7: while [ $n -lt 3 ]; do'
you have two dos after while. you should read more to fix syntax error.
You still lack a do in the for. The proper syntax is for var in list ... ; **do** stuff; done

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.