shell学习三十--综合应用

前端之家收集整理的这篇文章主要介绍了shell学习三十--综合应用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
for循环打印下面这句话中的字母数不大于6的单词 I am oldboy teacher welcome to wolf training class. [root@node01 day13]# vi arr01.sh arr=(I am oldboy teacher welcome to wolf training class.) for wolf in ${arr[@]} do if [ ${#wolf} -le 6 ] then echo $wolf fi done [root@node01 day13]# sh arr01.sh I am oldboy to wolf class. [root@node01 day13]# vi arr02.sh #!/bin/sh arr=(I am oldboy teacher welcome to wolf training class.) for((i=0;i<${#arr[*]};i++)) do if [ ${#arr[$i]} -le 6 ] then echo ${arr[$i]} fi done [root@node01 day13]# sh arr02.sh I am oldboy to wolf class. [root@node01 day13]# vi for.sh #!/bin/sh char="(I am oldboy teacher welcome to wolf training class.)" for n in $char do if [ ${#n} -le 6 ] then echo $n fi done [root@node01 day13]# sh for.sh (I am oldboy to wolf #!/bin/sh for i in I am oldboy teacher welcome to wolf training class. do [ ${#i} -le 6 ] && echo $i done [root@node01 day13]# sh for01.sh I am oldboy to wolf class. [root@node01 day13]# vi awk.sh #!/bin/sh echo "I am oldboy teacher welcome to wolf training class."|awk '{for(i=1;i<=NF;i++) if(length($i)<=6)print $i}' [root@node01 day13]# sh awk.sh I am oldboy to wolf class. [root@node01 day13]#vi wc.sh #!/bin/sh for i in I am oldboy teacher welcome to wolf training class. do [ `echo $i|wc -L` -le 6 ] && echo $i done ------------------------------------------ a、for b、对字符串长度进行判断 c、wc -L d、变量子串${#wolf} e、expr length f、awk 原文链接:https://www.f2er.com/bash/389383.html

猜你在找的Bash相关文章