Added loops
This commit is contained in:
@@ -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 a variable range of numbers.](#loop-over-a-variable-range-of-numbers)
|
||||||
* [Loop over an array.](#loop-over-an-array)
|
* [Loop over an array.](#loop-over-an-array)
|
||||||
* [Loop over an array with an index.](#loop-over-an-array-with-an-index)
|
* [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)
|
* [Loop over files and directories.](#loop-over-files-and-directories)
|
||||||
* [File handling](#file-handling)
|
* [File handling](#file-handling)
|
||||||
* [Read a file to a string.](#read-a-file-to-a-string)
|
* [Read a file to a string.](#read-a-file-to-a-string)
|
||||||
@@ -601,6 +602,14 @@ for i in "${!arr[@]}"; do
|
|||||||
done
|
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.
|
## Loop over files and directories.
|
||||||
|
|
||||||
Don’t use `ls`.
|
Don’t use `ls`.
|
||||||
|
|||||||
Reference in New Issue
Block a user