Help with for loop

Hi..
I want to know the syntax which reads the value inside a file.
for example a file has data :
1
2
3
4
5

how will i make a variable "i" read the values inside the file (let's say "data")

Thanks in advance.

is this what you mean?

while read i
do
   echo $i
done<data
1 Like

Frank, I want help with for loop..

for example I have a list of IPs in a file and I want to perform a ping test on each of them, and I want my for loop to read each and every IP and do a ping test one after the other. What would the syntax be?

Why the prejudice towards for? :slight_smile:

The while loop as suggested by frank is an excellent suggestion.

Read the below, maybe it will help you see the reason:

DontReadLinesWithFor - Greg's Wiki

hey..thanks...
am a newbie in shell scripting and was taking for loop to do all the things that it does in C.. So wanted to go for for loop instead of while..
Thanks for that both of you really.. I mean, it is really good to know where are the cases where for loop fails :slight_smile: