Bash (Scripting) - Count values in a list

by
Jeremy Canfield |
Updated: September 09 2024
| Bash (Scripting) articles
Let's say you have an list of fruit. # can be used to return the number of elements in a list.
#!/bin/bash
fruits=(banana apple orange grapes)
echo "The \"fruits\" array contains ${#fruits[@]} elements"
Which should return the following.
4
Did you find this article helpful?
If so, consider buying me a coffee over at