5.2.1 Control statements
JP1/Advanced Shell supports the control statements listed below. For details, see 9.6 Script control statements.
case
Executes one of the processes depending on the contents of character strings.
for
Executes the same processing repeatedly by changing the value sequentially.
if
Executes the processing that satisfies each condition by branching out the processing depending on conditions.
until
Executes the same processing repeatedly until the condition is satisfied.
while
Executes the same processing repeatedly while the condition is satisfied.
You can specify command substitution and any commands other than extended script commands at the following locations in the control statements.
- Locations where command substitution can be specified
Expressions and patterns in case statements
wordlist in for statements
- Locations where command substitution and any commands other than extended script commands can be specified:
Condition 1 (condition that follows if) and condition 2 (condition that follows elif) in if statements
Conditions in until statements
Conditions in while statements
The return code of a specified command is not applied as the return code of the job and job step. When execution of control statements is completed, the return code of the last command executed within the block of control statements becomes the return code of the job and job step.
However, if any of the conditions listed below is satisfied, the return code of a specified command is applied as the return code of the job and job step. When a job step is completed, the return code of the specified command becomes the return code for the job and job step.
The specified command is the exit or return command, not a command substitution.
The specified command is a special built-in command, not a command substitution, and it resulted in an error.
The specified command, which is neither 1 nor 2 above, resulted in an error and the control statement was in a job step for which stop was specified for the onError attribute.
If you want to apply the return code of a command resulting in an error as the job's return code, such as when a job is to result in an error in JP1/AJS, specify the control statement in a job step for which stop is specified for the onError attribute.
The following shows examples of the if statement:
- Example 1:
if `cmdA true` <-- cmdA is a nonexistent command name. then echo "true" else echo "false" <-- The else clause is executed. fi # At this point, the return code of the job is 0.
In example 1, if cmdA for command substitution specified in condition 1 of the if statement is a nonexistent command name, the condition is determined to be false, in which case echo "false" in the else clause is executed. At the point where the if statement is completed, the return code of the job is 0.
- Example 2:
#-adsh_step_start S1 -onError stop if `cmdA true` <-- cmdA is a nonexistent command name. then echo "true" else echo "false" fi #-adsh_step_end <-- The job step is cancelled without executing the then or else clauses. # The return code of job step S1 and the job at this point is 127.
In example 2, if cmdA for command substitution specified in condition 1 of the if statement is a nonexistent command name, the job step is cancelled without executing either the then or the else clause of the if statement. When the job step is completed, the return code of the job is 127, which indicates that the specified command does not exist. For details about the definitions of job steps and the onError attribute, see 9.5.9 #-adsh_step_start command, #-adsh_step_error command, #-adsh_step_end command (defines a job step) in 9.5 Extended script commands.