偶然在网上看到一道测试题,貌似是某家公司的面试题,要求如下
使用shell判断abc test hello world this important life中字母超过4个的字符串
#!/bin/bash for i in abc test hello world this important life do if [ `echo $i|wc -L` -gt 4 ] then echo $i fi done
输出结果如下:
test@test:~$ /bin/sh test.sh hello world important
这里我们可以使用wc -L来判断字符串的长度,例如:
echo abcderf|wc -L
7
echo abcderf|wc -L 7
转载于:https://blog.51cto.com/addam/1390732