1. Computing

Discuss in my forum

Bash Guide For Beginners


10.3.2. Length of a variable

Using the ${#VAR } syntax will calculate the number of characters in a variable. If VAR is "*" or "@" , this value is substituted with the number of positional parameters or number of elements in an array in general. This is demonstrated in the example below:


 [bob in ~] echo $SHELL
 [bob in ~] echo ${#SHELL}
 [bob in ~] ARRAY=(one two three)
 [bob in ~] echo ${#ARRAY}

* License

* Bash Guide For Beginners Index

  1. About.com
  2. Computing
  3. Linux

©2014 About.com. All rights reserved.