- Bash Script: Get the length of any given String

Below is a simple script to get the length of any string.

#!/bin/bash
echo "enter the sting: "
read str;

countStringLength() {
        echo `echo -n $1 | wc -c`

        # Or can use the below trick to get the string length
        # I prefer to use the first one - easy to use and easy to remember
        echo ${#1}
}
countStringLength $str




source:http://linuxpoison.blogspot.com/2012/05/13578167751853.html