How to Count String Length using Shell

Tags: April 2, 2012 7:14 AM

Bash Variable: The POSIX Way

$ MYSTRING="Speed of Light"
$ echo ${#MYSTRING}
14

Using wc

$ echo -n "Speed of Light"
14

Using expr

This is not POSIX complaint.

$ expr length "Speed of Light"
14

References

Share on Facebook Twitter

0 comments:

Post a Comment