Linux shell script read file line by line

The following are different ways of reading a txt file line by line in linux shell. To fun the following scripts, you should create a "test.txt" file under the same directory with your script.

Method 1

Use file names as parameter to the shell script.

while read line
    echo "Text read from file - $name"
done < $1

Linux command to run:

chmod +x
./ test.txt

Method 2

Put file name inside of shell script.

while IFS= read -r line
        # display $line or do somthing with $line
        echo "$line"
done <"$file"

Linux command to run:

Category >> Linux  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";