This piece of code is working absolutely fine when I am executing it individually
for i in {1..13}
do
echo "<td class = 'loop'>
</td>"
done
But when I am putting this inside a bash script I am getting only one iteration,instead of 13 iteration.
The whole script looks something like
while read variable
do
//something
done<a.txt
for i in {1..13}
do
echo "<td class = 'loop'>
</td>"
done
Can any one help me out.
EDIT
#/!/bin/bash
while read host
do
y=$(($y+1))
count=$(ping -c $COUNT $host | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
if [ -n "$host" ]; then
echo "<td class ='statuscellred'>" >>table1.html
echo "$host" | cut -d'.' -f1 >> table1.html
echo "</td>" >> table1.html
if [ $(($y % 13)) -eq 0 ] ; then
echo "</tr>">>table1.html
echo "<tr>">>table1.html
fi
else
echo "<td class ='statuscellblanck'>" >>table1.html
echo "$host" >> table1.html
echo "</td>" >> table1.html
if [ $(($y % 13)) -eq 0 ] ; then
echo "</tr>">>table1.html
echo "<tr>">>table1.html
fi
fi
else
if [ -n "$host" ]; then
echo "<td class ='statuscellgreen'>" >>table1.html
echo "$host" | cut -d'.' -f1 >> table1.html
echo "</td>" >> table1.html
if [ $(($y % 13)) -eq 0 ] ; then
echo "</tr>">>table1.html
echo "<tr>">>table1.html
fi
else
echo "<td class ='statuscellblanck'>" >>table1.html
echo "$host" >> table1.html
echo "</td>" >> table1.html
if [ $(($y % 13)) -eq 0 ] ; then
echo "</tr>">>table1.html
echo "<tr>">>table1.html
fi
fi
fi
done < server1.txt
for i in {1..13}
do
echo "<td class = 'loop'>
</td>">>table1.html
done
and here is server1.txt
1.com
2.com
3.com
4.com
5.com
7.com
8.com
9.com
11.com
13.com
15.com
Based on the posted code, the shebang line is not formed correctly. It should be:
with no leading spaces (posted version has an extra
/in it). As it stands, if you execute that in a shell it’ll be interpreted by the current shell, and the first line is merely a comment.[taken from my comment as it appears to have resolved the OP’s problem]