![Forrest logo](/images/logo.png)
for:tldr:56125
for: Execute the given commands for each of the specified items.
$ for ${variable} in ${item1 item2 ---}; do ${echo "Loop is executed"}; done
try on your machine
This command is a simple loop written in bash scripting language. It allows you to perform a specific action repeatedly for each item in a given list.
Here's a breakdown of the command:
-
for ${variable} in ${item1 item2 ---};
:for
: This keyword initiates a loop.${variable}
: This is the name of the variable that will hold the value of each item in the list.in
: This keyword specifies the list of items to iterate over.${item1 item2 ---}
: This is the list of items to loop over. In this example, it contains three items:item1
,item2
, and---
(represented as a placeholder).
-
do ${echo "Loop is executed"}
:do
: This keyword marks the start of the commands to be executed within the loop.${echo "Loop is executed"}
: This is the command that will be executed each time the loop iterates. In this case, it is anecho
command that prints the message "Loop is executed".
-
done
:done
: This keyword marks the end of the loop and signifies that all iterations have been completed.
When you run this command, the loop will iterate over the list of items (item1
, item2
, and ---
). For each iteration, it will execute the echo
command, which will display the message "Loop is executed". The loop will continue until all items in the list have been processed.
This explanation was created by an AI. In most cases those are correct. But please always be careful and
never run a command you are not sure if it is safe.