awk way
bogon:conf macname$ echo "abcde" | awk '{print length($0)}' 5
Using $ {# str} to get the length of the string
bogon:conf macname$ a="abcdef" bogon:conf macname$ echo ${#a} 6
wc way (note containing a newline)
bogon:conf macname$ echo "abcde" | wc -c 6
reference:
https://www.jb51.net/article/121290.htm