SYNTAX

    while [options] [<condition>]


OPTIONS

-h (--help) bool

Display help.


ARGUMENTS

[<condition>]

The given condition is evaluated each time through the loop. If not specified the loop continues forever (or until a break statement). The conditional is an fshell expression that must return zero (KErrNone) in order for the loop to continue. It is common to use a var command in the condition, although any command can be used if desired. Any further arguments or options will be coalesced into this one. [string]


DESCRIPTION

Support for conditional loops in fshell scripts.

Execute all the following statements (up until endwhile) repeatedly while condition evaluates to KErrNone. The semantics are the same as for C-style while loops. For example:

    export I 0
    while var I lessthan 10
        echo "Loop iteration $I"
        var I add 1
    endwhile
    # $I is now 10

Indentation of the block is optional but recommended. There are a couple of restrictions on usage of while and endwhile that don't apply to most other fshell commands:

Behaviour is unspecified if the above rules are ignored.

Nested while blocks are permitted providing there are the correct number of endwhile statements. Modifications to the environment within the while block (or even within the conditional, although this isn't recommended) are visible outside the block. In other words there is no scoping associated with the block.

Be careful when using dollar-expansion in the condition argument - it will be expanded when the while command is constructed, ie before being used as the conditional, unless it is single-quoted. It is allowed to put multiple statements in the condition, but note it must be quoted to prevent it appearing as if it is the while command that should be in the pipeline. Eg the correct way of including two conditions in the while statement is:

    while 'var I == 0 && exists some_file'
        ...
    endwhile

Note: If you are executing a script using source and kill the script while it is exectuting a while block (by for example pressing CTRL-C) it will not terminate the while block. This is not unique to the while command, no command that is in the middle of running in a source script will be terminated when pressing CTRL-C - it's just a bit more obvious when you're using the while command.


SEE ALSO

endwhile, break, continue, repeat, if


COPYRIGHT

Copyright (c) 2011 Accenture. All rights reserved.