Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add example for looping over command output #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ See something incorrectly described, buggy or outright wrong? Open an issue or s
* [Loop over a (*small*) range of numbers](#loop-over-a-small-range-of-numbers)
* [Loop over a variable range of numbers](#loop-over-a-variable-range-of-numbers)
* [Loop over the contents of a file](#loop-over-the-contents-of-a-file)
* [Loop over the output of a command](#loop-over-the-output-of-a-command)
* [Loop over files and directories](#loop-over-files-and-directories)
* [VARIABLES](#variables)
* [Name a variable based on another variable](#name-a-variable-based-on-another-variable)
Expand Down Expand Up @@ -649,6 +650,14 @@ while IFS= read -r line || [ -n "$line" ]; do
done < "file"
```

## Loop over the output of a command

```shell
command|while IFS= read -r line || [ -n "$line" ]; do
printf '%s\n' "$line"
done
```

adigitoleo marked this conversation as resolved.
Show resolved Hide resolved
## Loop over files and directories

Don’t use `ls`.
Expand Down