Bash - declare and loop over array
How to declare an array and loop over it?
1
2
3
4
5
6
7
# declare array: https://www.gnu.org/software/bash/manual/html_node/Arrays.html
declare -a myArray=("Linux Mint" "Fedora" "Red Hat Linux" "Ubuntu" "Debian" )
# loop through it: https://www.freecodecamp.org/news/bash-array-how-to-declare-an-array-of-strings-in-a-bash-script/
for str in ${myArray[@]}; do
echo $str
done
Sources:
- declare array: https://www.gnu.org/software/bash/manual/html_node/Arrays.html
- loop through an array: https://www.freecodecamp.org/news/bash-array-how-to-declare-an-array-of-strings-in-a-bash-script/
This post is licensed under CC BY 4.0 by the author.