Length of parameter

suggest change
# Length of a string
$ var='12345'
$ echo "${#var}"

Note that it’s the length in number of characters which is not necessarily the same as the number of bytes (like in UTF-8 where most characters are encoded in more than one byte), nor the number of glyphs/graphemes (some of which are combinations of characters), nor is it necessarily the same as the display width.

# Number of array elements
$ myarr=(1 2 3)
$ echo "${#myarr[@]}"

# Works for positional parameters as well
$ set -- 1 2 3 4
$ echo "${#@}"

# But more commonly (and portably to other shells), one would use
$ echo "$#"

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents