mirror of
https://github.com/dylanaraps/pure-sh-bible
synced 2024-05-17 21:06:36 +02:00
Merge cbfb9c394a
into 26bc7e8d6c
This commit is contained in:
commit
0e4c8e9e20
26
README.md
26
README.md
|
@ -47,6 +47,7 @@ See something incorrectly described, buggy or outright wrong? Open an issue or s
|
|||
* [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 files and directories](#loop-over-files-and-directories)
|
||||
* [Filter the argument list](#filter-the-argument-list)
|
||||
* [VARIABLES](#variables)
|
||||
* [Name a variable based on another variable](#name-a-variable-based-on-another-variable)
|
||||
* [ESCAPE SEQUENCES](#escape-sequences)
|
||||
|
@ -675,6 +676,31 @@ for dir in ~/Downloads/*/; do
|
|||
done
|
||||
```
|
||||
|
||||
# Filter the argument list
|
||||
|
||||
This is a general technique for looping over the argument list, dropping
|
||||
any arguments for which some `<test>` fails.
|
||||
|
||||
``` shell
|
||||
for arg do
|
||||
shift
|
||||
<test> || continue
|
||||
set -- "$@" "$arg"
|
||||
done
|
||||
```
|
||||
|
||||
**Example:**
|
||||
|
||||
Drop arguments that are not directories. For simple, one-liner
|
||||
tests like this we can use `&&` instead of `|| continue`.
|
||||
|
||||
``` shell
|
||||
for arg do
|
||||
shift
|
||||
[ -d "$arg" ] && set -- "$@" "$arg"
|
||||
done
|
||||
```
|
||||
|
||||
# VARIABLES
|
||||
|
||||
## Name and access a variable based on another variable
|
||||
|
|
Loading…
Reference in a new issue