VAR_SHELL_GETLENGTH parameter (defines the unit for the lengths of variable values that are replaced in format ${#variable})
- Organization of this page
Format
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
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.