Before going through a language in detail, you should understand the concept of variables. A variable is used to store data, which can be changed later. In the Linux environment there are two types of variables:
System Variables
These types of variables are defined by Linux Operating System. Generally, capital letters are used for system variables.
For example, BASH, BASH_VERSION, HOME, LOGNAME, etc.
The output of the program is shown below:
User Defined Variables
These types of variables are defined by users. Generally, lowercase letters are used to define the variables. A name of a variable can be started with only letters (a to z or A to Z) and the underscore. But it can contain digits (0 to 9) in any other position, except the starting position.
A user-defined variable can be declared as:
Array
An array is a collection of homogeneous data stored in contiguous memory space. The following example shows, how data is stored in memory.
In the shell script, the first element is stored at index 0.
The example shown above will print 3rd element of the array.
To print all the elements of the array, you can use echo ${lang[@]} or echo ${lang[*]}.
Read-only variables
The value of a read-only variable can't be changed.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.