When the value of an environment variable is to be expressed as an integer, software interprets the value of the variable as follows:
-
Any leading white space is skipped. If the next character is a plus sign (+) or a minus sign (-), it is also skipped. If the next character was a minus sign, the final numeric value is negated.
-
If the value starts with a number other than zero, it may contain only the digits zero through nine, and it is considered a decimal number.
-
If the value starts with “0x” or “0X”, it may contain the digits zero through nine, as well as the letters “a” through “f” and “A” through “F”. At least one digit or letter must follow the “x” or “X”. The value is treated as a hexadecimal number.
-
If the value starts with a zero and is not followed by a “x” or “X”, it may contain only the digits zero through seven, and it is treated as an octal number.
Otherwise, the variable does not represent a numeric value. In most cases, an error message is printed. In a few cases, the numeric value is simply taken to be zero.
Examples of numeric values provides examples of numeric values and how they are interpreted by software.
Numeric value |
Meaning |
---|---|
"0" |
The value zero. |
" 10" |
The value ten. The leading white space is ignored. |
"+010" |
The value eight, octal. |
"0x10" |
The value sixteen, hexadecimal. |
"-123" |
The value negative one hundred twenty-three. |
"abc" |
An illegal value, may be treated as zero. |
"019" |
An illegal value, leading zero makes it octal, but octal numbers cannot contain a nine. This value may be treated as zero. |
"1 " |
An illegal value, leading white space is ignored but trailing white space is not. This value may be treated as zero. |
"0X" |
An illegal value, at least one digit or letter must follow the “OX”. This value may be treated as zero. |
"- 23" |
An illegal value, embedded white space is not permitted. This value may be treated as zero. |