#!/bin/bash head -n 3 $file | while read line; do # do something. e.g. echo $line done # あるいは #!/bin/bash for line in `head -n 3 $file`; do # do something done