Three methods available for calculating string length:
echo “$str” awk ‘{print length($0)}’
expr length “$str”
echo “$str”wc -c
But the The values obtained by the three methods will be 1 more, possibly because the terminator is also included in the calculation.
There are three ways to determine whether a string is empty:
if [ "$str" = "" ]
if [ x"$str" = x ]
if [ -z "$str" ]
Note: You must put double quotes, otherwise some commands will report errors, so you should develop a good habit!