how to read line by line from file in bash script? how to read line by line from file in bash script? bash bash

how to read line by line from file in bash script?


Like this?

while IFS= read line ; do   something "$line"done <"$file"

Here is a brief test:

while IFS= read line ; do echo "$line"; done <<<"$(echo -e "a b\nc d")"a bc d


You can you readarray (bash 4+)

readarray lines < "$file"

then

for line in "${lines[@]}"; do    echo "$line"done

Note that by default readarray will even include the line-end character for each line