The ABLE shell supports simple variables, these variables are in the form:
name=
[value
]
where the name
must start with a letter
of the alphabet (upper or lower case) or an underscore
(_) and continue with letters of the
alphabet, numbers or an underscore (_). The
value
may contain any arbitrary numeric or
textural value and when omitted is a null (empty) string. The
value
may need to be quoted in order to get a
correct assignment.
The non-volatile variables are also accessible from within the shell. The variable form is identical to that of simple variables with one exception, the body of the variable name will contain a full stop (.).
Any changes to the non-volatile variables will not be made permanent until a nvsave command is issued.
A non-volatile variable my be “unset”, an unset parameter will use the system default value. A variable may be unset by assigning to an empty value or using the nvunset command.
The nvclear command can be used to restore the values back to the defaults. The nvsave should not be used to attempt to save these values, this would result in the current settings state being saved not the default values.
The value is interpreted differently depending on the
settings data type, as with simple variables the
value
may need to be quoted to get a correct
assignment.
Table 4.1. Non-volatile data types
Variable type | Values |
---|---|
Boolean | “on” and “off” (“true” or “false” and “0” or “1” may also be used). |
Numeric | Any numeric value using only the digits between 0 and 9. |
String | Any alphanumeric string. |
In addition to simple assignment non-volatile variables may be changed with the nvset command. The syntax of the command is
nvset
{variable
} {value
}
Where the
is one of
those shown in Appendix A, Non-Volatile Variables Reference and
the value is correct for the variables type.variable
The positional parameters are similar to the simple variables except the variable name is a positive integer number. Each parameter is set from the arguments to the shell or script when it was started.
The single digit 0 has special meaning and is set to the name of the shell or script.
Positional parameters cannot be assigned with the normal assignment operator and are read only.
When the tenth or later positional parameters are referenced they must be disambiguated using curly braces this is shown fully in Example 4.3, “Accessing positional parameters”
In addition to simple variables there are a small number of “special” variables which do not match the syntax for simple variable names. These typically access specific information within the shell and are read only.
Table 4.2. Special variables
Variable name | Value |
---|---|
? | Exit status of last command |
- | Shell parameters |
* | All the positional parameters separated by the first character of the IFS variable. |
# | The number of positional parameters. |
Variables are accessed within the shell by using the
dollar symbol followed by the variable name
$name
. The variable name my also be
surrounded by curly braces ${name
}.
The curly brace form is less ambiguous because if the braces are omitted the shell may not be able to distinguish between a variable name and the text surrounding it. The curly brace form is unambiguous as the variable name is clearly delimited.
Example 4.2. Using curly braces to disambiguate variables
This example shows a variable
myvariable
being set and then displayed
using the two forms showing the ambiguity problem.
>myvariable=hello >echo foo $myvariable bar foo hello bar >echo foo$myvariablebar foo >echo foo${myvariable}bar foohellobar >
Special care must be taken of positional parameters, the simple version with no braces is limited to the nine single digits 1-9 to access the the later positional parameters curly braces must be used.
Example 4.3. Accessing positional parameters
This example shows accessing the first positional parameter, then the first positional parameter when the tenth was meant and finally accessing the tenth parameter correctly.
>echo $1 one >echo $10 one0 >echo ${10} ten >
There are a small number of shell variables which have special meaning to the shell environment itself. These variables generally affect some aspect of the shell environment. Several of these variables have defaults which are assigned by the shell upon initialisation.
Table 4.3. Variables with special meanings
Variable | Meaning |
---|---|
PS1 | This variable contains the text of the prompt to use, which allows users to alter their prompt or scripts to use the same prompt as the shell. This value is set to > by default. |
PS4 | This variable is the forth level prompt, it is used when the -x switch is in operation to preface output lines. This value is set to + by default. |
PWD | This variable is the present working directory
within the filesystem. Consult Section 3.4, “Filesystem navigation”
for more details. This
value is set to / by
default. |
OLDPWD | The previous working directory. Consult Section 3.4, “Filesystem navigation” for more details. |
IFS | The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read command. This value is set to “space tab newline” by default. |
PATH | The search path for commands. A series of directories to search for external commands. The directores are colon separated and may include the PWD which is represented by a single dot. |
ABLE_VERSION | The version of ABLE currently running. The
major and minor version numbers are available seperately
as ABLE_VERSION0 and
ABLE_VERSION1 respectively. |