linux shell语法综合实践1取出字符超过6个的单词

#!/bin/bash

arr=(      #定义数组  arr =()
I am english teacher welcome to english training class
)

len=${#arr[*]}  #取数组长度不是$(#arr[*])
echo $len
for(( i=0; i < len; i++ ))
do                                                     #[]中括号各空一个空格否则报错 testfor.sh: line 10: [1: command not found
    if [ `expr length ${arr[$i]}` -le 6 ]  #[]中是-le非<=报错testfor.sh: line 10: =: No such file or directory
      then                  #取变量的值是$变量即arr[$i]非arr[i]
       echo "${arr[$i]}"#$(arr[i])报错testfor.sh: line 12: arr[0]: command not found
    fi

done

猜你喜欢

转载自blog.csdn.net/qq_34412985/article/details/79923766
今日推荐