How to read a file line by line with Bash
Sometimes you want to do actions per line instead of the complete file at once. Here is an example that you can use to read the file line by line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/bin/bash run_cmd_file() { while read line do chr=${line:0:1} case $chr in "#" ) # ignore commented lines ;; * ) echo "$line" ;; esac done < $1 } run_cmd_file filename |