Length of an string is number of characters in it. It is straight forward to know the length of an string for normal text.

This post explains ways to count the number of characters in a string with UTF encoding.

String length in Bash

There are number of ways we can find the length of an string.

First way, use ${#variable} syntax.

In this, find the string variable length.

msg="Hello World."
count=${#msg} 

echo $count # 12

Output:

12

Second way, using wc -m pipe symbol with echo string variable.

It can find the length using string or variable

echo -n 'Hello World.' | wc -m; # 12

result=`echo -n $msg | wc -m`   
echo $result # 12

result1=`echo  $msg | wc -m`   
echo $result1 # 12

Output:

12
12
12