Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 536 Bytes

10.md

File metadata and controls

24 lines (20 loc) · 536 Bytes

题目要求

用shell打印下面这句话中字母数小于6的单词。 Bash also interprets a number of multi-character options.

核心要点

  • for循环遍历所有单词
  • wc -L获取字符串长度

参考答案

#!/bin/bash
c="Bash also interprets a number of multi-character options."
n=`echo $c|awk -F '[ +-.]' '{print NF}'`
for ((i=1;i<$n;i++))
do
    l=`echo $c|awk -F '[ +-.]' -v j=$i '{print $j}'|wc -L`
    if [ $l -lt 6 ]
    then
        echo $c|awk -F '[ +-.]' -v j=$i '{print $j}'
    fi
done