From b16263439440c493d44a62fe265fb386dfa26265 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 15 Jun 2018 16:40:31 +1000 Subject: [PATCH] Added loops --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) 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`.