Shell 编程 until语句

本篇主要写一些shell脚本until语句的使用。
计算1-50的和
#!/bin/bash
i=0
s=0
until [ $i -eq 51 ];do
let s+=i;let i++
done
echo $s
[root@localhost ~]# vim sum.sh
[root@localhost ~]# chmod +x sum.sh
[root@localhost ~]# ./sum.sh
1275
为指定用户发送在线消息
#!/bin/bash
username=$1
# 判断格式是否正确
if [ $# -lt 1 ] ;then
echo "Usage:`basename $0` <username> [message]"
exit 1
fi
# 判断用户是否存在
if grep "^$username:" /etc/passwd > /dev/null ;then :
else
echo "用户不存在"
exit 1
fi
# 判断用户是否在线,不在则每5s联系一次
until who|grep "$username" > /dev/null ;do
echo "用户不在线"
sleep 5
done
# 发送信息
mes=$*
echo $mes | write $username
[root@localhost ~]# vim message.sh
[root@localhost ~]# chmod +x message.sh
[root@localhost ~]# ./message.sh
Usage:message.sh <username> [message]
[root@localhost ~]# ./message.sh zhangsan hello
用户不存在
[root@localhost ~]# useradd zhangsan && echo "000000" | passwd --stdin zhangsan
Changing password for user zhangsan.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# ./message.sh zhangsan hello
用户不在线
用户不在线
^C
[zhangsan@localhost ~]$
[root@localhost ~]# ./message.sh zhangsan hello
[zhangsan@localhost ~]$
Message from root@localhost on pts/0 at 02:25 ...
zhangsan hello
EOF
Shell 编程 until语句的更多相关文章
- shell编程——if语句【转载】
(2)shell编程——if语句_macg_新浪博客http://blog.sina.com.cn/s/blog_6151984a0100ekl6.html shell编程——if语句转载 if 语句 ...
- 【转载】shell编程——if语句 if -z -n -f -eq -ne -lt
shell编程中条件表达式的使用 if 条件then Commandelse Commandfi 别忘了这个结尾 If语句忘了结尾fites ...
- Shell 编程 循环语句
本篇主要写一些shell脚本循环语句的使用. for 循环 指定次数 #!/bin/bash for ((i=1;i<=10;i++)) do echo $i done [root@localh ...
- Shell 编程 case语句
本篇主要写一些shell脚本case语句的使用. 字符判断 #!/bin/bash read -p "请输入一个字符:" char case $char in [a-z]|[A-Z ...
- Shell 编程 条件语句
本篇主要写一些shell脚本条件语句的使用. 条件测试 test 条件表达式 [ 条件表达式 ] 文件测试 -d:测试是否为目录(Directory). -e:测试文件或目录是否存在(Exist). ...
- shell编程——if语句 if -z -n -f -eq -ne -lt
if 条件then Commandelse Commandfi 别忘了这个结尾 If语句忘了结尾fitest.sh: line 14: sy ...
- shell编程——if语句
if 语句格式 if 条件 then Command else Command fi 别忘了这个结尾 If语句忘了结尾fi test.s ...
- Linux Shell编程case语句
http://blog.csdn.net/dreamtdp/article/details/8048720 case语句适用于需要进行多重分支的应用情况. case分支语句的格式如下: case $变 ...
- 1.Shell编程循环语句(if 、while、 until)
循环语句 for循环语句 读取不同的变量值,用来逐个执行同一组命令 格式: for 变量名 in 取值列表 do 命令序列 done 示例:批量创建用户并设置密码 [root@localhost da ...
随机推荐
- VIJOS-P1059 积木城堡
洛谷 P1504 积木城堡 https://www.luogu.org/problem/P1504 JDOJ 1240: VIJOS-P1059 积木城堡 https://neooj.com/oldo ...
- git clean (11)
#delete untracked files git clean -f # delete untracked files and directories git clean -fd # -n opt ...
- [LeetCode] 24. Swap Nodes in Pairs 成对交换节点
Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...
- css line-height [转]
原文: http://www.cnblogs.com/dolphinX/p/3236686.html https://www.cnblogs.com/yangjie-space/p/4858132.h ...
- git合并不同仓库下的分支
1.把lib合并到pro $ git remote -v origin git@192.168.1.1:lib.git (fetch) origin git@192.168.1.1:lib.git ( ...
- 【ASP.NET Core分布式项目实战】(五)Docker制作dotnet core控制台程序镜像
Docker制作dotnet core控制台程序镜像 基于dotnet SDK 新建控制台程序 mkdir /home/console cd /home/console dotnet new cons ...
- 如何备份开拓者TBQuant的策略文件
备份 "C:\TBQuant_V1.1.0.9_X64\users\你的用户名\Strategy\data\strategy.bin" 这个文件即可.
- axios详解
一.说明 Axios是一个基于Promise(ES6中用于处理异步的)的HTTP库(HTTP客户端),用于浏览器和node.js中,API. 浏览器中创建XMLHttpRequests 从node.j ...
- python 进程数据通信
进程通信的第一种方式from multiprocessing import Process,Queue def f(q): q.put([42,2,'hello']) print('zi q id:' ...
- java识别死亡或者存活的对象
那些内存需要回收 内存回收是对运行时内存区域的内存回收,其中程序计数器.虚拟机栈.本地方法栈3个区域随线程而生,随线程而灭:栈中的栈帧随着方法的进入和退出而有条不紊的执行着出栈和入栈操作.每一个栈帧中 ...