Friday, March 7, 2008

Find String Length : BASH


Suppose:

$ VAR="Bash Scripting"

Now to find the length of the above string, I have found 3 different ways:

$ echo "${#VAR}"
14

$ expr length "$VAR"
14

$ echo $VAR | awk '{print length}'
14

3 comments:

Graham M said...

Thanks for this. It's always nice to see a few different ways of doing something.

Tyzoid D said...

how about echo -n $VAR | wc -m?

Jadu Saikia said...

@Tyzoid D, thanks a lot.

© Jadu Saikia www.UNIXCL.com