The pound sign counts things.
- If it's just
$#
, it's the number of positional parameters, like $1
, $2
, $3
. (Not counting $0
, mind you.)
- If it's
${#var}
, it's the number of characters in the expansion of the parameter. (String length)
- If it's
${#var[@]}
, it's the number of elements in the array. Since bash arrays are sparse, this can be different from the index of the last element plus one.