[root@zyl scripts]# cat array02.sh
#!/bin/sh
array=(William Randolph Hearst was one of the richest men in 1903.)
#1
for word in ${array[*]}
do
if [ ${#word} -le 6 ];then
echo $word
fi
done
echo -e "\033[32m======================\033[0m"
#2
for ((i=0; i<${#array[*]}; i++))
do
if [ ${#array[$i]} -le 6 ];then
echo ${array[$i]}
fi
done
echo -e "\033[32m======================\033[0m"
#3
chars="William Randolph Hearst was one of the richest men in 1903."
for n in $chars
do
[ ${#n} -gt 6 ] && {
echo $n
}
done
转载于:https://blog.51cto.com/zhagyilig/1852674