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. If conditional is a ‘{
subcommand }’ or ‘(lisp form)’, the condition is
satisfied if the command’s exit status is 0.
if conditional { true-commands }
if conditional { true-commands } { false-commands }
Evaluate true-commands if conditional is satisfied; otherwise, evaluate false-commands.
unless conditional { false-commands }
unless conditional { false-commands } { true-commands }
Evaluate false-commands if conditional is not satisfied; otherwise, evaluate true-commands.
while conditional { commands }
Repeatedly evaluate commands so long as conditional is satisfied.
until conditional { commands }
Repeatedly evaluate commands until conditional is satisfied.
for var in list… { commands }
Iterate over each element of list, storing the element in var and evaluating commands. If list is not a list, treat it as a list of one element. If you specify multiple lists, this will iterate over each of them in turn.