To find the length of an array in Bash, you can use the ${#array[@]}
syntax, which returns the number of elements in the array. For example:
array=("apple" "banana" "cherry") echo "${#array[@]}"
This will output 3
, which is the number of elements in the array.
Alternatively, you can use the ${#array[*]}
syntax, which also returns the number of elements in the array.
You can also use the ${#array[i]}
syntax to find the length of a specific element in the array. For example:
echo "${#array[1]}"
This will output the length of the second element in the array, which is 6
in this case (the string "banana" has a length of 6).