if [options] <condition>
Display help.
Execute the following statements if the given condition evaluates to 0 (KErrNone). Any further arguments or options will be coalesced into this one. [string]
Support for conditional execution in fshell scripts.
Execute all the following statements (up until an else
or endif
statement) if the condition
evaluates to KErrNone. The semantics are the same as for C-style if (condition) {...} else {...}
statements. For example:
if var ERR == 0 echo "No error!" endif
One or more else
statements are allowed, as are multiple statements in each block:
if var ERR == 0 echo "No error!" source DoSomethingElse.script else if var ERR == -5 echo "Not supported." else if var ERR == -14 echo "In use." else error $ERR "Unrecognised error!" endif
As with the while command, the if
, else
and endif
statements cannot be backgrounded, redirected or participate in pipelines. In other words they must appear on a line by themselves (although comments and whitespace are permitted on that line).
Nested if and while blocks are permitted providing there are the correct number of endif/endwhile statements. Modifications to the environment within the if or else statements are visible outside the block. In other words there is no scoping associated with the block.
The if
command is only for use in scripts - behaviour is undefined if you type it in at an interactive command prompt.
Copyright (c) 2011 Accenture. All rights reserved.