Printing the Arrays
After declaring the array, if we wanted to display all the elements in the array we can use the @ symbol.
#!/bin/usr/env bash declare -a sport=( [0]=football [1]=cricket [2]=hockey [3]=basketball ) echo "${sport[@]}"
echo "${array_name[@]}"
We use the [@] as an index to the array to display all the elements. All the elements are printed with space-separated, The quotes around the variable expands and print all the elements in the array.
Bash Scripting – Array
Arrays are important concepts in programming or scripting. Arrays allow us to store and retrieve elements in a list form which can be used for certain tasks. In bash, we also have arrays that help us in creating scripts in the command line for storing data in a list format. In this article, we will understand the basics of arrays in bash scripting.