From 50a970825028e74e0a849e98d1d9b2f7dde7da10 Mon Sep 17 00:00:00 2001 From: Emily Grace Seville Date: Tue, 15 Feb 2022 01:58:56 -0800 Subject: [PATCH] for: refresh (#7482) --- pages/common/for.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/pages/common/for.md b/pages/common/for.md index 53e93f5f5..51b40d853 100644 --- a/pages/common/for.md +++ b/pages/common/for.md @@ -1,12 +1,24 @@ # for -> Shell loop over parameters. -> More information: . +> Perform a command several times. +> More information: . -- 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`