bash size of array 1

bash size of array

## define it
distro=("redhat" "debian" "gentoo")
 
## get length of $distro array
len=${#distro[@]}
 
## Use bash for loop 
for (( i=0; i<$len; i++ )); do echo "${distro[$i]}" ; done

Here is what the above code is Doing:
1. First, we define an array named distro and assign three values to it.
2. Then, we get the length of the array using the # operator.
3. Finally, we use a for loop to iterate through the array and print each element.

Similar Posts