linux poison RSS
linux poison Email

Bash Script: Get the length of any given String

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

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


Post a Comment

Related Posts with Thumbnails