海诗网 知识百科 shell脚本for循环(shell脚本for循环 计算1到100的和)

shell脚本for循环(shell脚本for循环 计算1到100的和)

shell脚本for循环, shell脚本中的for循环是什么?让我们一起来看看:

使用for循环在shell脚本中编写脚本通常用于确定输入的用户名是否存在。如果不存在,则创建用户并设置密码,否则程序会继续提示用户,即提示重新输入新创建的用户名。

for命令中for i的各种用法介绍如下:

For the I in File 1, File 2 and File 3

for i in /boot/*

for i in /etc/*.conf

For I, the unit is $(seq -w 10)-"01-10 of equal width.

For {1…10} years of I

for i in $( ls )

for I in $( file)

“$ @”中的For i使用所有位置参数,可以缩写为for I。

shell脚本for循环 计算1到100的和

需要注意的是,bash shell支持C类型for循环。

示例代码如下:

#!/bin/bash

j=$1

for ((i=1; i=j; i++))

do

touch file$i echo file $i is ok

done

$ @:所有位置变量的内容

$ #:位置变量的数量

$0:文件名

$ *:所有位置变量的内容。

shell脚本for循环 计算1到100的和

for循环的一般代码格式是:

对于列表中的变量名

do

command1

command2

.

commandN

done

参考示例:

示例1

输入代码:

for loop in 1 2 3 4 5

do

echo The value is: $loop

done

输出结果是:

The value is: 1The value is: 2The value is: 3The value is: 4The value is: 5

示例2

如果您编写一个脚本来清除所有arp缓存记录,示例代码如下:

#!/bin/bash

for i in $(arp | tail -n +2|tr -s |cut -d -f1)

do

arp -d $i

done

shell脚本for循环,以上就是本文为您收集整理的shell脚本for循环最新内容,希望能帮到您!更多相关内容欢迎关注。

本文来自网络,不代表海诗网立场,转载请注明出处:https://www.hallse.com/n/169514.html
      

ubuntu修改root密码(ubuntu设置root密码)

发表回复
联系我们
联系我们

在线咨询: QQ交谈

邮箱: 3587015498@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们
微信扫一扫关注我们
关注微博
返回顶部