Shell编程中for循环结构是怎么样的

54次阅读
没有评论

共计 752 个字符,预计需要花费 2 分钟才能阅读完成。

丸趣 TV 小编给大家分享一下 Shell 编程中 for 循环结构是怎么样的,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

for i in {取值范围}

do

循环体

done

求取 1 -100 数字的和、找出 1 -100 中能被 2 整除的数字、找出 1 -100 中的素数、找出 1 -100 种能被 3 整除的数字

#!/usr/bin/env bash

#

# Author: bavdu

# Email: bavduer@163.com

# Github: https://github.com/bavdu

# Date: 2019/**/**

sum=0

for i in {1..100}

do

let total=$sum+$i #或者写成 let total=i++

done

printf $total\n

测试生产环境中的主机存活性

#!/usr/bin/env bash

#

# Author: bavdu

# Email: bavduer@163.com

# Github: https://github.com/bavdu

# Date: 2019/**/**

ip_alive.txt

ip_down.txt

export segment= 192.168.161

for i in {2..254}

do

{

ping -c1 $segment.$i /dev/null

if [$? -eq 0];then

printf alive: $segment.$i\n ip_alive.txt

else

printf down: $segment.$i\n ip_down.txt

fi

}

done

wait

printf $(date +%Y-%m-%d_%k:%M:%S) -exec filename:$0\n

看完了这篇文章,相信你对“Shell 编程中 for 循环结构是怎么样的”有了一定的了解,如果想了解更多相关知识,欢迎关注丸趣 TV 行业资讯频道,感谢各位的阅读!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-04发表,共计752字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)