Changhyun Cho Changhyun Cho - 1 year ago 104
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download