Linux Know-How provides a collection of introductory texts on often needed Linux skills. |
Home Bash Guide for Beginners More on variables Using the declare built-in | |||||||||||||||||||
See also: General assignment of values, Constants | |||||||||||||||||||
Search the VIAS Library | Index | |||||||||||||||||||
Using the declare built-inUsing a declare statement, we can limit the value assignment to variables. The syntax for declare is the following: declare OPTION(s) VARIABLE=value The following options are used to determine the type of data the variable can hold and to assign it attributes: Table 10-1. Options to the declare built-in
Using + instead of - turns off the attribute instead. When used in a function, declare creates local variables. The following example shows how assignment of a type to a variable influences the value.
Note that Bash has an option to declare a numeric value, but none for declaring string values. This is because, by default, if no specifications are given, a variable can hold any type of data:
As soon as you restrict assignment of values to a variable, it can only hold that type of data. Possible restrictions are either integer, constant or array. See the Bash info pages for information on return status.
|
|||||||||||||||||||
Home Bash Guide for Beginners More on variables Using the declare built-in |