Languages
[Edit]
EN

Bash - check array size

3 points
Created by:
Teilsa
1105

This article will show you how to check the array size in Bash.

Quick solution:

length=${#array[@]}

or:

length=${#array[*]}

 

Practical examples

@ based solution

It is possible to use ${#array[@]} to get array size .

#!/bin/bash

array=(Tom Kate Mary)
length=${#array[@]}

echo $length

Example output:

3

 

* based solution

It is possible to use ${#array[*]} to get array size .

#!/bin/bash

array=(Tom Kate Mary)
length=${#array[*]}

echo $length

Example output:

3
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - check array size
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join