1. Computing

Discuss in my forum

Bash Guide For Beginners

By

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
 /bin/bash
 
 [bob in ~] echo ${#SHELL}
 9
 
 [bob in ~] ARRAY=(one two three)
 
 [bob in ~] echo ${#ARRAY}
 3
 

* License

* Bash Guide For Beginners Index

  1. About.com
  2. Computing
  3. Linux

©2014 About.com. All rights reserved.