In this section, we will consider how to use shell arrays in UNIX. A shell variable is capable enough to hold a single value. These variables are called scalar variables.
Shell supports a different kind of variable called an array variable. This can hold several values at the same time. Arrays supply a scheme of grouping a set of variables. In its place of creating a new name for each variable that is essential, you can use a single array variable that stores all the other variables.
All the naming rules discuss for Shell Variables would be relevant while naming arrays.
The differentiation between an array variable and a scalar variable can be explained as follows.
Understand you are trying to represent the names of different students as a set of variables. Each of the individual variables is a scalar variable as follows –
We can employ a single array to store all the above mention names. Following is the simplest process of creating an array variable. This helps allocate a value to one of its indices.
Here array name is the name of the array, index is the index of the item in the array that you desire to set, and value is the value you want to set for that item.
As an instance, the following commands –
If you are using the kasha shell, here is the syntax of array initialization –
If you are using the bash shell, here is the syntax of array initialization –
Following you have set any array variable, you access it as follows –
Here array name is the name of the array, and index is the index of the value to be access. Following is an instance to realize the concept –
The above instance will create the following result –
You can access all the items in an array in one of the following conduct –
Here array name is the name of the array you are attracted in. Following illustration will help you recognize the model –
The above instance will make the following result –
Unix/Linux Related Interview Questions
|Perl Scripting Interview Questions||Shell Scripting Interview Questions|
|Python Interview Questions||Core Java Interview Questions|
|Linux Interview Questions||Linux Embedded systems Interview Questions|
|Red Hat Linux System Administration Interview Questions||IBM AIX Interview Questions|
|Sybase Interview Questions||IBM AIX 7 Administration Interview Questions|
|Unix Shell Scripting Interview Questions||Linux Shell Scripting Interview Questions|
Unix/Linux Related Practice Tests
|Perl Scripting Practice Tests||Shell Scripting Practice Tests|
|Python Practice Tests||Core Java Practice Tests|
|Linux Practice Tests||Linux Embedded systems Practice Tests|
|Red Hat Linux System Administration Practice Tests||IBM AIX Practice Tests|
|Sybase Practice Tests||IBM AIX 7 Administration Practice Tests|
|Autosys Practice Tests|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.