string length expansion
The ${#name} form, which expands to the number of characters in a variable, or ${#array[@]} for the number of elements.
In more detail
It only works inside curly braces. For an array, putting the at sign inside gives the element count rather than the length of the first element.
Examples
echo "${#name}"echo "${#files[@]}"Related terms
- parameter expansion — Replacing a dollar sign and a variable name with the variable's value, optionally transformed by an operator inside curly braces.
- shell array — A variable that holds a numbered list of separate values, written in bash as names=(one "two words" three).
Taught in
- Arrays, And Why Dollar At Is Not Dollar Star — Bash Scripting & Command Line Automation
- Parameter Expansion: Defaults, Length, Slices — Bash Scripting & Command Line Automation
- POSIX sh Versus Bash — Bash Scripting & Command Line Automation