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!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn