shell 數組
案例一:
打印下面這句話中字母數大於 5 的單詞
Tip:The only constant is changeshell
#!/bin/bash 方法一: arr=(The only constant is change) for i in ${arr[*]} do if [ `expr length $i` -gt 5 ];then echo $i fi done echo "-----------" 方法二: for ((i=0;i<${#arr[*]};i++)) do if [ ${#arr[$i]} -gt 5 ];then echo ${arr[i]} fi done
輸出結果:編程
constant change ----------- constant change
Shell 腳本調試