for循环和shell数组小脚本案例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了for循环和shell数组小脚本案例相关的知识,希望对你有一定的参考价值。
利用for循环和shell数组打印下面这段话英文字母数不大于5的单词:
You have the most beautiful age, do not disappoint your best self
老规矩,首先分析:
1.找重点,for 和数组
2.字母书小于5的单词
value=(You have the most beautiful age, do not disappoint your best self)
for ((i=0;i<${#value[*]};i++))
do
if [ ${#value[$i]} -lt 5 ]
then
echo ${value[$i]}
fi
done
第二种方法
for word in ${value[*]}
do
if [ expr length $word
-lt 5 ];then
echo $word
fi
done
[root@node1 ~]# sh test.sh
You
have
the
most
age,
do
not
your
best
self
测试成功
?方法还有很多,大家可以试试~
以上是关于for循环和shell数组小脚本案例的主要内容,如果未能解决你的问题,请参考以下文章