Examples of bash arrays

array=( one two three )
files=( "/etc/passwd" "/etc/group" "/etc/hosts" )
limits=( 10, 20, 26, 39, 48)

To print values

printf "%s\n" "${array[@]}" 
printf "%s\n" "${files[@]}" 
printf "%s\n" "${limits[@]}"

Looping through the elements in the array

arrayOfNumbers=( one two three )
for i in "${arrayOfNumbers[@]}"
do
  echo "using $i from arrayOfNumbers"
  # do some action
done
comments powered by Disqus