johnbakers
johnbakers

Reputation: 24771

Use of < in while loop

I've seen much documentation and examples of using while in a bash script but none that explain what the < is doing in this:

while read p; do 
echo $p
done < $filename

What exactly is the program flow in the above, and how does < work?

Upvotes: 0

Views: 59

Answers (1)

devnull
devnull

Reputation: 123608

You might want to refer to redirection.

Saying:

command < filename

executes command with filename as the input.

The command that you mention reads one line at a time from the file denoted by $filename.

You might also want to refer to help while and help read.

Upvotes: 2

Related Questions