Bash script - loop question

Hi Folks,

I have a loop that goes through an array and the output is funky.

sample:

array=( 19.239.211.30 )
for i in "${array[@]}"
do
echo $i
iperf -c $i -P 10 -x CSV -f b -t 50 | awk 'END{print '$i',$6}' >> $file
done

Output:

19.239.211.30
19.2390.2110.3 8746886

seems that when the $i after the awk is printed something happens to it.

Any ideas?

Thanks.

---------- Post updated at 06:55 PM ---------- Previous update was at 06:09 PM ----------

Answered my own question:

replace '$i' with ��${i}�� = win

Your fix is sufficient; the awk needs to see the string in quotes. You don't need the curly braces.
For further safety, in the shell, you should quote variables in command arguments:

echo "$i"
iperf ... "$i" ...
awk 'END{print "'"$i"'",$6}'

The latter becomes better readable as

awk 'END{print s,$6}' s="$i"

Hi,

Thanks for the response!

Advice taken.