本文共 782 字,大约阅读时间需要 2 分钟。
until命令简介:
until循环:适用于循环次数未知的场景,且条件不满足就进行循环,条件满足则退出。
1.命令格式:
语法:
until CONDITION; do
statement
...
done
2.命令功能:
until循环:适用于循环次数未知的场景,且条件不满足就进行循环,条件满足则不循环退出。
3.命令参数:
until CONDITION; do condition:进入循环的条件
statement
...
done
4.命令实例:
1、查看用户是否登录,使用until循环体
[root@xuelinux tmp]# vim until1.sh
#!/bin/bash
#program:
#使用until循环体查看用户是否在线
#history donggen 2016-11-07-17:20
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bash
export PATH
until who | grep "donggen" &> /dev/null; do
echo "donggen is not exist."
done
echo "donggen is login."
[root@xuelinux tmp]# chmod +x until1.sh
donggen is not exist.
donggen is not exist.
donggen is not exist.
donggen is not exist.
donggen is login.