Changhyun Cho Changhyun Cho - 4 months ago 12
Bash Question

Meaning of ${#variable[@]}

Recently, I've been starting work about shell scripting.

When I was reading some script, suddenly that variable appeared.

${#variable[@]}


It looks like array variable but I don't know exactly what it is.
What is that? and What's the meaning of this syntax?

Answer

In Bash, that gives you the number of elements in an array. From the Arrays section in Bash's documentation:

${#name[subscript]} expands to the length of ${name[subscript]}. If subscript is ‘@’ or ‘*’, the expansion is the number of elements in the array.

Comments