9.3.2 : command (expands arguments)
Syntax
: [arguments]
Description
This command expands arguments. It always returns 0 as the return code.
For example, you can omit the else or elif clause from an if statement, but not the then clause. In such a case, specify the : command for the then clause as follows, to indicate that no action is to be taken when the condition is satisfied:
if [conditional-expression]; then : # Takes no action if the result of the conditional expression is true. else cmd1 # Executes command if the result of the conditional expression is false. fi
Arguments
- arguments
Specifies arguments that are to be expanded as explained below.
- Job definition script specification example
set -x NUMBER=1 : $NUMBER
- Result that is output to the standard error output
+ NUMBER=1 + : 1 # Outputs the expansion result of the variable NUMBER.
Therefore, by specifying a variable substitution in the arguments argument, you can check whether a value is stored in the variable and substitute a value if there is no value.
- Job definition script specification example
STRING01=ABC : ${STRING01:=DEF} # Because variable STRING01 stores ABC, no action is taken. : ${STRING02:=GHI} # Because variable STRING02 is undefined, CHI is substituted. echo $STRING01 $STRING02 # "ABC GHI" is output to the standard output.
If variable substitution in the format ${variable:?word} or ${variable?word} is specified in the arguments argument and no value is stored in variable, processing terminates with an error with 1 as the return code.
Note that this command accepts no options. If an option is specified, it is ignored and processing continues.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 |
Error termination
|
Notes
If the value of n is 0 or smaller or exceeds 2,147,483,647, overflow will occur. The overflow digits are ignored and processing continues. We recommend that you specify a value in the range from 1 to 2,147,483,647.
If the command syntax of this special built-in command is invalid, it exits the shell that is executing the command.
Example
Only expand the arguments.
: $test