1. for循环
语法1:for NAME [in WORDS ... ] ; do COMMANDS; done
#!/bin/bashif [[ $# -lt 1 ]] ; then echo no param!!!; exit; fi for a in "[email protected]" ; do echo hello$a > ${a} ; done
如果参数的个数小于1,直接退出。否则把hello+参数名依次重定向到参数名作为文件名的文件。
[email protected]:命令行所有的参数
语法2:for (( exp1; exp2; exp3 )) do COMMANDS; done
for (( a=1 ; a < 11 ; a = a + 1 )) ; do echo $a ; done
循环打印1到10
2while循环
语法1:while COMMANDS; do COMMANDS; done
语法2: (( exp1))
while (( exp2 )) ; do
COMMANDS
(( exp3 ))
done
#!/bin/bash (( count = $# )) (( a = 1 )) while (( a <= count )) ; do echo $1; shift; (( a = a+1 )) done
循环打印命令的参数
$#:命令的参数个数;
shift:参数左移一位
原文地址:https://www.cnblogs.com/fireinthehole/p/10088886.html
时间: 2024-10-18 16:22:49