Skip to content
Justice Tech School

Arrays

Bash has indexed arrays. ${a[@]} lists all items and ${#a[@]} counts them.

Example
a=(red green blue)
a+=(pink)
echo "${a[0]} ${a[-1]} ${#a[@]}"
for c in "${a[@]}"; do echo "- $c"; done
echo "${a[@]:1:2}"

Result

red pink 4
- red
- green
- blue
- pink
green blue

Exercise

Count items.

echo ${a[@]}

Quiz Test

How do you list all items?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.