企业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

 

相关文章:

  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2022-12-23
  • 2021-12-08
猜你喜欢
  • 2021-12-29
  • 2022-12-23
  • 2021-06-15
  • 2021-05-15
  • 2021-07-19
  • 2022-12-23
  • 2022-01-04
相关资源
相似解决方案