Here’s a Bash script that reads the array and prints the values. On top of that, you can print the index if you need.
Let us go details of Vector and Matrix. A single-value array is called Vector, and if it has multiple Values, it’s called Matrix.
Not only numbers, but you can also have strings in arrays. In real-time, you can find this type of array.
A loop logic you need here to read the elements of the array. So I have used for loop.
As a first step, I have initialized the numbers with numeric values from 1 to 5. In addition, I have initialized total1 and total2 to ‘0’.
First, for loop reads all the elements. Second, the total1 appends array elements with ‘0’.
The let command do computation(It sums up all the numbers and gives a count). So it describes the function of the script.
Result of Array Script
You must be logged in to post a comment.