1. [root@zyl scripts]# cat array02.sh

  2. #!/bin/sh

  3. array=(William Randolph Hearst was one of the richest men in 1903.)

  4. #1

  5. for word in ${array[*]}

  6. do

  7. if [ ${#word} -le 6 ];then

  8. echo $word

  9. fi

  10. done

  11. echo -e "\033[32m======================\033[0m"

  12. #2

  13. for ((i=0; i<${#array[*]}; i++))

  14. do

  15. if [ ${#array[$i]} -le 6 ];then

  16. echo ${array[$i]}

  17. fi

  18. done

  19. echo -e "\033[32m======================\033[0m"

  20. #3

  21. chars="William Randolph Hearst was one of the richest men in 1903."

  22. for n in $chars

  23. do

  24. [ ${#n} -gt 6 ] && {

  25. echo $n

  26. }

  27. done