1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-07-25 10:35:25 +02:00

for: refresh (#7482)

This commit is contained in:
Emily Grace Seville 2022-02-15 01:58:56 -08:00 committed by GitHub
parent 233b10de4f
commit 50a9708250
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,12 +1,24 @@
# for
> Shell loop over parameters.
> More information: <https://man.archlinux.org/man/for.n>.
> Perform a command several times.
> More information: <https://www.gnu.org/software/bash/manual/bash.html#Looping-Constructs>.
- Perform a command with different arguments:
- Execute the given commands for each of the specified items:
`for argument in 1 2 3; do {{command $argument}}; done`
`for {{variable}} in {{item1 item2 ...}}; do {{echo "Loop is executed"}}; done`
- Perform a command in every directory:
- Iterate over a given range of numbers:
`for d in *; do (cd $d; {{command}}); done`
`for {{variable}} in {{{from}}..{{to}}..{{step}}}; do {{echo "Loop is executed"}}; done`
- Iterate over a given list of files:
`for {{variable}} in {{path/to/file1 path/to/file2 ...}}; do {{echo "Loop is executed"}}; done`
- Iterate over a given list of directories:
`for {{variable}} in {{path/to/directory1/ path/to/directory2/ ...}}; do {{echo "Loop is executed"}}; done`
- Perform a given command in every directory:
`for {{variable}} in */; do (cd "${{variable}}" || continue; {{echo "Loop is executed"}}) done`