Added loops

This commit is contained in:
Dylan Araps 2018-06-15 16:40:31 +10:00
parent 8bd977f5d3
commit b162634394
1 changed files with 9 additions and 0 deletions

View File

@ -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.
Dont use `ls`.