Bash provides several straightforward methods to determine the length of a string

Method 1: Parameter expansion

This is the way i use most → ${#variable}

mystring="this is a string in a variable"
echo "${#mystring}"

Method 2: expr

Using the expr command

mystring="this is a string in a variable"
expr length "$mystring"

expr lenght "this is a literal string"

Method 3: wc

Using the wc command

mystring="this is a string in a variable"
echo -n "$mystring" | wc -c

echo -n "this is a literal string" | wc -c
Here, we use echo -n to print the string without a trailing newline