先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前在阿里
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Linux运维全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
3、使用for循环和if,筛选出以下单词中字符数大于等于6的单词:I am teacher oldchang and I like eating and sleeping
[root@shell day05]# cat for-ip.sh #!/bin/bash for ((i=1;i<255;i++));do ping -c 1 -w 1 10.0.0.$i &>/dev/null if [ $? -eq 0 ];then echo "10.0.0.$i 可以ping通!" else echo "10.0.0.$i 不可以ping通!" fi done wait [root@shell day05]# sh for-ip.sh 10.0.0.1 可以ping通! 10.0.0.21 可以ping通! ^Z [4]+ Stopped sh for-ip.sh
4、for循环打印99乘法表
[root@shell lianxi]# cat for99-1.sh #!/bin/bash #倒三角排序 for ((i=9 ;i>=1;i--));do for ((j=1;j<=i;j++));do echo -en "${j}x$i=$(($i\*$j))\t" #第一种方法计算 done echo done #正三角排序 for ((i=1;i<=9;i++));do for ((j=1;j<=i;j++));do echo -en "${j}x$i=`expr $i\*$j|bc`\t" #第二种方法计算 done echo done [root@shell lianxi]# sh for99-1.sh 1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81 1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 1x5=5 2x5=10 3x5=15 4x5=20 5x5=25 1x4=4 2x4=8 3x4=12 4x4=16 1x3=3 2x3=6 3x3=9 1x2=2 2x2=4 1x1=1 1x1=1 1x2=2 2x2=4 1x3=3 2x3=6 3x3=9 1x4=4 2x4=8 3x4=12 4x4=16 1x5=5 2x5=10 3x5=15 4x5=20 5x5=25 1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81
5.给出一个网段,如10.0.0.0/24,如何判断网段内的所有ip是否能联通
[root@shell day05]# cat for-ip.sh #!/bin/bash ############################################################## # File Name: for\_ip.sh # Version: V1.0 # Author: lcx # Organization: www.oldboyedu.com ############################################################## #for i in 10.0.0.{1..254} #do # ping -c 2 -w 2 $i &>/dev/null # if [ $? -eq 0 ];then # echo $i 可以ping通! # else # echo $i 不可以ping通 &>/dev/null # fi #done for ((i=1;i<255;i++));do ping -c 1 -w 1 10.0.0.$i &>/dev/null if [ $? -eq 0 ];then echo "10.0.0.$i 可以ping通!" else echo "10.0.0.$i 不可以ping通!" fi done wait [root@shell day05]# sh for-ip.sh 10.0.0.1 可以ping通! 10.0.0.21 可以ping通! ^Z [4]+ Stopped sh for-ip.sh
2.循环的流程控制
break、continue、exit、return
2.1 break
[root@shell day05]# vim break.sh
1 #!/bin/bash
2 ##############################################################
3 # File Name: break.sh
4 # Version: V1.0
5 # Author: lcx
6 # Organization: www.oldboyedu.com
7 ##############################################################
8 for ((i=0;i<10;i++));do
9 echo $i
10 if [ $i -eq 3 ];then
11 break
12 fi
13 done
[root@shell day05]# sh break.sh
0
1
2
3
2.2 contunue
[root@shell day05]# cat break.sh
#!/bin/bash
##############################################################
# File Name: break.sh
# Version: V1.0
# Author: lcx
# Organization: www.oldboyedu.com
##############################################################
for ((i=0;i<10;i++));do
echo $i
if [ $i -eq 3 ];then
continue
fi
done
echo "hello"
[root@shell day05]# sh break.sh
0
1
2
3
4
5
6
7
8
9
hello
流程控制的测试脚本
[root@shell day05]# vim for-bcer.sh
#!/bin/bash
##############################################################
# File Name: for-bcer.sh
# Version: V1.0
# Author: lcx
# Organization: www.oldboyedu.com
#############################################################
#循环流程控制break、continue、exit、return的区别和对比
if [ $# -ne 1 ];then
# 如果传参个数部位1,则打印下面的使用提示,提示四个命令作为参数
echo $"usage:$0 {break|continue|exit|return}"
exit 1 #退出脚本
fi
function test(){
for((i=0;i<5;i++));do
if [ $i -eq 3 ];then
$\*; #"$\*" 就是接收函数以外的参数,是{break|continue|exit|return}其中一个
fi
echo $i
done
echo "I am in func." #函数内循环外的输出提示
}
test $\* # 这里的$\*为参数的传参
func_ret=$? # 接收并测试函数返回值
if [ `echo $\*|grep return|wc -l` -eq 1 ];then # 如果传参中含有return
echo "return exit status: $func\_ret" # 则提示return退出的状态码
fi
echo "OK"
执行结果
[root@shell day05]# sh for-bcer.sh
usage:for-bcer.sh {break|continue|exit|return}
[root@shell day05]# sh for-bcer.sh break
0
1
2
I am in func.
OK
[root@shell day05]# sh for-bcer.sh continue
0
1
2
4
I am in func.
OK
[root@shell day05]# sh for-bcer.sh exit
0
1
2
[root@shell day05]# sh for-bcer.sh return
0
1
2
return exit status: 0
OK
3. 数组
普通数组:只能使用整数作为索引
关联数组:可以只用字符串作为数组索引
3.1 普通数组
[root@shell day05]# oldboy[2]=lcx
[root@shell day05]# oldboy[3]=gyj
[root@shell day05]# oldboy[4]=wx
[root@shell day05]# declare -a #查看数组
[root@shell day05]# echo $oldboy
ljg
[root@shell day05]# echo ${oldboy[3]}
gyj
[root@shell day05]# echo ${oldboy[4]}
wx
[root@shell day05]# echo ${oldboy[@]} #"@"和"\*"相同
ljg wd lcx gyj wx gds lfx hyj rh
[root@shell day05]# echo ${oldboy[\*]}
ljg wd lcx gyj wx gds lfx hyj rh
[root@shell day05]# echo ${!oldboy[\*]} #查看数组所有的索引下标
0 1 2 3 4 5 6 7 8
[root@shell day05]# echo ${#oldboy[\*]} #查看数组元素个数
8
[root@shell day05]# oldboy=(ljg wd lcx gyj wx gds lfx hyj rh) #数组的批量赋值
[root@shell day05]# echo ${oldboy[\*]}
ljg wd lcx gyj wx gds lfx hyj rh
3.2 删除数组
[root@shell day05]# unset oldboy
[root@shell day05]# echo ${oldboy[@]}
[root@shell day05]# declare -a oldboy #定义空数组
**先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前在阿里**
**深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**
**因此收集整理了一份《2024年最新Linux运维全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。**
![img](https://img-blog.csdnimg.cn/img_convert/cc9e01a49a81679509550649f990df2b.png)
![img](https://img-blog.csdnimg.cn/img_convert/ec2250a34a6b658a7d6f896dca4be00b.png)
![img](https://img-blog.csdnimg.cn/img_convert/744c037baec5cfc81bb2aa364e9cf3c6.png)
![img](https://img-blog.csdnimg.cn/img_convert/af287713f0d923d6421a488673992b3f.png)
![img](https://img-blog.csdnimg.cn/img_convert/160fa244a6fd275aad067120ed5498d3.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**
-F3XgyXfE-1715331195542)]
[外链图片转存中...(img-79wpvphh-1715331195542)]
[外链图片转存中...(img-pSYhOgIb-1715331195542)]
[外链图片转存中...(img-BvtMu3hr-1715331195542)]
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**