Bootstrap FreeKB - Bash (Scripting) - Count values in a list
Bash (Scripting) - Count values in a list

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 7d2ee4 in the box below so that we can be sure you are a human.