Previous: Remote Access, Up: Commands [Contents][Index]
Because Eshell commands can not (easily) be combined with Lisp forms, Eshell provides command-oriented control flow statements for convenience.
Most of Eshell’s control flow statements accept a conditional.
This can take a few different forms. If conditional is a dollar
expansion, the condition is satisfied if the result is a non-nil
value. Alternately, conditional may be a subcommand, either in
command form, e.g. ‘{subcommand}’; or in Lisp form,
e.g. ‘(lisp form)’. In that case, the condition is
satisfied if the subcommand’s exit status is 0.
if conditional true-subcommandif conditional true-subcommand else false-subcommandEvaluate true-subcommand if conditional is satisfied; otherwise, evaluate false-subcommand. Both true-subcommand and false-subcommand should be subcommands, as with conditional.
You can also chain together if/else forms, for example:
if {[ -f file.txt ]} {
echo found file
} else if {[ -f alternate.txt ]} {
echo found alternate
} else {
echo not found!
}
unless conditional false-subcommandunless conditional false-subcommand else true-subcommandEvaluate false-subcommand if conditional is not satisfied;
otherwise, evaluate true-subcommand. Like above, you can also
chain together unless/else forms.
while conditional subcommandRepeatedly evaluate subcommand so long as conditional is satisfied.
until conditional subcommandRepeatedly evaluate subcommand until conditional is satisfied.
for var in sequence… subcommandIterate over each element of sequence, storing the element in
var and evaluating subcommand. If sequence is a
range of the form begin..end, iterate over each
integer between begin and end, not including end. If
sequence is not a sequence, treat it as a list of one element.
If you specify multiple sequences, this will iterate over each of them in turn.
Previous: Remote Access, Up: Commands [Contents][Index]