Changhyun Cho Changhyun Cho - 11 months ago 52
Bash Question

Meaning of ${#variable[@]}

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

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


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?


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.