Go to the first, previous, next, last section, table of contents.
Variables are names which can have values associated with them. The name can be any combination of alphabetic, numeric or underscore characters, providing that the first character is not numeric. The values can be a character string, an integer, or an array of other values. See the Builtin vartype.
Most variables are characters strings. Such a string can contain any
character other than the nul character.
When a variable is first used, it is assumed to be a string variable
unless it is used in a context that specifically requires an integer variable.
An integer variable can hold a signed value, the range of which is machine specific but usually such that it fits into a 32 bit word. That is approximately plus or minus two thousand million.
When assigning a string to an integer variable, the string gets processed by the arithmetic unit to convert it to an integer. "' what happens on error FIXME Thus assigning the string "4+5" to an integer variable will place the value `9' in it, whereas assigning the same string to a string variable will place the value "4+5" in it.
When a variable name appears in a string that is being processed by the arithmetic unit, the named variable is automatically converted into an integer variable. If it was not already an integer variable, its value will first be converted to a string (if necessary) and then converted to an integer by a recursive call to the arithmetic unit.
An array variable contains an arbitrary list of other variables. These variables can be integers, strings or other arrays. There is no need for every element of an array to be the same type. Array elements can also be undefined. Indeed an array could be considered to be an infinite list of variables, each of which is one of string, integer, array or undefined, providing that there is only a finite number of non-undefined variables.
Each array has, associated with it, a separator character. This provides information on how to convert a string to an array, and an array to a sting. When an array variable has a string assigned to it, the string is broken in to pieces based on the separator character. If the separator character is undefined, then the string is broken up using the "Blank Substitution" algorithm based on the IFS (Input Field Separator) variable. If the separator character is defined, then instances of that character in the string are taken to be break points. Two adjacent separator characters will create an empty field in the break up. Once the string has been broken up, the piece are assigned individually to consecutive elements of the array. All entries in the array after the last one assigned to become undefined.
When assigning to an element of an array that is undefined, the type is taken to be the same as the type of element zero in the array.
When a array in to be converted to a string, each element is converted to a string, and these strings are joined by single instances of the separator character. If there is no separator character, the first character of IFS is used. If there is no such first character, a space is used.
Arrays are indexed by integers from zero up. For most purposed, though, only the entries from 1 up are used. Thus when converting an array to a string, the "zeroth" entry is not included, unless specifically asked for. Similarly when assigning to an array, the "zeroth" entry is left unchanged.
It is possible to have a temporary array for which the separator character is defined to a non-character value. This is known as a "hard" array. When such an array is assigned to, the string must have been generated from expanding a similar hard array, and the individual entries in the second array are assigned to those of the first array without joining them together and then splitting them apart. When such an array is substituted into a wordlist, the elements of the array become individual words, no matter how the whole array substitution was quoted. Also, as mentioned above, value modifiers in variable substitution are applied to every element of a hard array individually.
Elements of an array are accessed by following the name of the array with and index surrounded by brackets. The index can take one of several forms. It can be an arithmetic expression as in
array[4+5]
which will provide the appropriate element of the array. It can be two expressions separated by a colon as in
array[2:20]
which will provide a new (temporary) sub-array containing the elements in the range. Note that this temporary array is indexed from one, so the following are equivalent:
array[2:20][4] array[5]
It can be an expression followed by an asterisk, such as
array[x*]
which provides a sub-array containing the elements from the given number onwards. Or it can be an expression followed by an at sign:
array[3@]
which provides a sub-array similar to where the asterisk is used, except that it is a hard array. If the number would be one, it can be omitted, thus
array[1*] array[*] array
are all equivalent.
For ease of access to the argument list, and for backward compatibility, the ARGV array can be accessed by just naming the index. This index must use literal decimal numbers as expressions, and cannot use the range index. Thus the following pairs are equivalent:
$2 ${ARGV[2]}
${0} ${ARGV[0]}
${3*} ${ARGV[3*]}
It should be noted that access array elements in Variable Substitution requires the use of braces. The expression
echo $array[4]
will not give the desired result.
The following variables have special meaning to the shell. so as to reduce confusion, they can not have their types changed from that described here.
cd
(change directory) command as a default.
Though the shell provides no default, this variable is usually defined in the
environment created by the
login
program.
cd
when looking for a named directory.
There is no default value.
This value should be an array with colon as the separator, but
currently it isn't. I should fix this.
ash
2.0.54).
The second two identify the host type and operating system that ash
was compiled to run under, for example
Apollo
SR10.
The last three give the date of the last change, as month, date and year.
e.g.
May 16 1991
DIGITS=0123456789ABCDEFThe default is to use lower case, and only to allow bases up to 36.
.
builtin).
Each of these three characters should be one of S,D,N,A,s,d,n,a.
They determine when path searching should actually be done, and when
the file name given should just be used as is.
If it is appropriate to the the file name as is, and that name doesn't
correspond to the appropriate type of object, then the path is tried
if the letter was uppercase, and the search fails immediately if the
letter was lowercase.
The letters stand for
/,
./,
../.
Go to the first, previous, next, last section, table of contents.