diff --git a/README.md b/README.md index beaeee5..d1bcf1c 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ scripts and not full blown utilities. * [Loop over a variable range of numbers.](#loop-over-a-variable-range-of-numbers) * [Loop over an array.](#loop-over-an-array) * [Loop over an array with an index.](#loop-over-an-array-with-an-index) + * [Loop over the contents of a file.](#loop-over-the-contents-of-a-file) * [Loop over files and directories.](#loop-over-files-and-directories) * [File handling](#file-handling) * [Read a file to a string.](#read-a-file-to-a-string) @@ -601,6 +602,14 @@ for i in "${!arr[@]}"; do done ``` +## Loop over the contents of a file. + +```shell +while read -r line; do + printf '%s\n' "$line" +done < "file" +``` + ## Loop over files and directories. Don’t use `ls`.