for循环和shell数组小脚本案例
2019-11-01 22:06
1546 查看
利用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
测试成功
方法还有很多,大家可以试试~
相关文章推荐
- shell脚本自动化部署XX的案例(附数组使用)
- shell 脚本中for循环遍历数组
- shell脚本 for循环、break跳出循环、continue结束本次循环
- linux shell脚本案例四:数组
- Shell脚本数组操作小结
- shell脚本使用两个数组,判断一个变量是否在数组里面的例子
- 大数据学习之路----linux系统的shell脚本编程案例(一)
- Shell脚本之for循环、while循环,if语句、case语句
- Shell脚本———比较整数大小经典案例
- shell脚本基础--数组
- 利用Shell开发跳板机功能脚本案例
- 【Shell脚本】怎样表示一个for循环
- shell脚本之shell数组
- 在 Shell 脚本里使用数组
- 数组-在Shell脚本中的基本使用介绍
- Shell 脚本知识回顾 (三) —— 替换、运算符、字符串、数组
- 在shell脚本中,如何写使用for循环
- linux操作shell脚本定义数组赋值取值
- Shell脚本数组操作小结
- shell脚本备份案例