str="i am vincen, i am twenty years old!"

for i in $str;do
    [ ${#i} -lt 4 ] && echo $i
done

 上面例子使用的是  ${#i} 来计算

 

var="i am vincen, and twenty years old!"
for i in $var;do
    if [ `expr length $i` -gt 3 ];then
        echo $i
    fi
done

 上面例子使用的是  expr length $i 来计算

 

[root@rhel6 ~]# echo oldboy | awk '{print length}'  
6

使用 awk print length来计算

 

[root@rhel6 script]# echo oldboy | wc -L
6

使用wc -L 更加简单

请注意 wc -l -L

  -l, --lines            print the newline counts
  -L, --max-line-length  print the length of the longest line

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案