在 shell 中用 ${#变量} 求字符串长度:iloveu 输出 6(真实字符数)。

echo iloveu | wc -c 输出 7,是因为 echo 在末尾补了换行符,wc -c 把它也算进去了,所以这种方式算长度不准确。

#shell-scripting