Shell面试题8:筛选符合长度的单词案例
企业Shell面试题8:筛选符合长度的单词案例
利用bash for循环打印下面这句话中字母数不大于6的单词(某企业面试真题)。
I am oldboy teacher welcome to oldboy trainingclass
解答:
[root@jenkins scripts]# sh danci.sh I am to [root@jenkins scripts]# cat danci.sh #!/bin/bash ############################################################## # File Name: danci.sh # Version: V1.0 # Author: gaobo # Organization: 641627690@qq.com # Created Time : 2017-12-05 15:47:33 # Description: ############################################################## my_word="I am oldboy teacher welcome to oldboy trainingclass" for i in ${my_word} do if [ `echo $i|wc -m` -le 6 ] then echo $i fi done
时来天地皆同力,运去英雄不自由