WhileLoops#
范例#
#!/bin/bash
myvar=1
#小于或者等于10
while [ $myvar -le 10 ]
do
echo $myvar
myvar=$(( $myvar + 1 ))
sleep 0.5
done运行
╭─ ~/shellTest ≡ ly@vmmin 12:10:33
╰─❯ ./71myscript_cls.sh
1
2
3
4
5
6
7
8
9
10数字会每隔0.5s就输出一次
对于myvar=$(( $myvar + 1 )) ,$((expression))形式表示算数运算,而且其中的空格是可以省略的
范例2#
#!/bin/bash
while [ -f ~/testfile ]
do
echo "As of $(date),the test file exists."
sleep 5
done
echo "As of $(date), the test ....has gone missing."用来测试文件是否存在,运行前先新建一下文件touch ~/testfile
运行一会后把文件删除,如图




































这里使用的是ga-hugo-theme(github中查找),并放到themes文件夹中



