10.3.2 isEmptyVar (evaluates to a null variable)
Syntax
isEmptyVar variable-name
Description
This command evaluates whether a value of variable is substituted for variable.
If either of the following conditions is met, 1 is output:
-
Variable is not defined
-
A variable is not substituted in variable
-
A blank character string is substituted in variable
This command outputs 0.
-
A variable with not less than one character is substituted in variable
Arguments
- variable-name
-
This command specifies a variable name to be determined.
If you specify the array, specify the array including element number (example: array[1]).
Output to the standard output
1 or 0.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
Not less than 1 |
Termination with an error |
Notes
-
Do not specify a variable name starting with "adsh" for the variable-name argument. If you specify such a variable name, it might conflict with the name of another variable used within the part and produce invalid output.
-
The character string that can be specified for variable-name is the same as character string that can be used as variable name. However, whether the character string can be specified is not verified.
Examples
typeset var1 isEmptyVar var1 # "1" is output. var1="" isEmptyVar var1 # "1" is output. var1=100 isEmptyVar var1 # "0" is output. #If variable var1 is null, return 1. result=$(isEmptyVar var1) if [[ $result -eq 1 ]]; then return 1 fi