Indexed Arrays
Arrays hold many values. Use arr=(a b c), ${arr[0]}, ${arr[@]} for all, ${#arr[@]} for the count, += to append, unset to remove and ${arr[@]:1:2} to slice.
Example
arr=(red green blue)
arr+=(yellow)
echo "${arr[1]} ${#arr[@]}"
echo "${arr[@]:1:2}"
unset "arr[0]"
echo "${arr[@]}"
for c in "${arr[@]}"; do echo -n "[$c]"; done; echoResult
green 4 green blue green blue yellow [green][blue][yellow]
Exercise
Count the items.
echo ${arr[@]}
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.