7.3.55 VAR_SHELL_GETLENGTH parameter (defines the unit for the lengths of variable values that are replaced in format ${#variable})
Syntax
VAR_SHELL_GETLENGTH {BYTE|CHARACTER}
Description
This parameter defines the unit for the lengths of variable values that are replaced in the format ${#variable}.
Operands
- BYTE
Specifies that the length of a value stored in variable in the format ${#variable} is to be replaced by the length in bytes.
- CHARACTER
Specified that the length of a value stored in variable in the format ${#variable} is to be replaced by the lengths in characters.
Examples
This example executes echo ${#CVAL} to obtain the length of the value of variable CVAL in which character string abcdef is set.
Specifying BYTE (replace by the length in bytes) in the VAR_SHELL_GETLENGTH parameter or omitting the VAR_SHELL_GETLENGTH parameter
The lengths of multibyte characters vary according to the execution environment. The following example assumes that a Linux UTF-8 environment is used:
CVAL=abcdef echo ${#CVAL}
Because abcdef is interpreted as being 12 bytes, 12 is output to the standard output.
Specifying CHARACTER (replace by the length in characters) in the VAR_SHELL_GETLENGTH parameter
CVAL=abcdef echo ${#CVAL}
Because abcdef consists of eight characters, 8 is output to the standard output.