for NAME [in WORDS ... ] ; do COMMANDS; done
Execute commands for each member in a list.
The for loop executes a sequence of commands for each member in a list of items. If in WORDS ...; is not present, then in "$@" is assumed. For each element in WORDS, NAME is set to that element, and the COMMANDS are executed.
Exit Status: Returns the status of the last command executed.
Examples
# for var in one two three; do echo $var; done
%ForLoop{
variable: "var",
items: [
%Word{parts: [{:literal, "one"}]},
%Word{parts: [{:literal, "two"}]},
%Word{parts: [{:literal, "three"}]}
],
body: [
%Command{name: "echo", args: [%Word{parts: [{:variable, "var"}]}]}
]
}
# for file in *.txt; do process $file; done
%ForLoop{
variable: "file",
items: [%Word{parts: [{:glob, "*.txt"}]}],
body: [...]
}
Summary
Types
@type t() :: %Bash.AST.ForLoop{ body: [Bash.Statement.t()], condition: String.t() | nil, exit_code: 0..255 | nil, init: String.t() | nil, items: [Bash.AST.Word.t()], iteration_count: non_neg_integer() | nil, meta: Bash.AST.Meta.t(), state_updates: map(), update: String.t() | nil, variable: String.t() | nil }