本篇主要写一些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语句的更多相关文章

  1. shell编程——if语句【转载】

    (2)shell编程——if语句_macg_新浪博客http://blog.sina.com.cn/s/blog_6151984a0100ekl6.html shell编程——if语句转载 if 语句 ...

  2. 【转载】shell编程——if语句 if -z -n -f -eq -ne -lt

    shell编程中条件表达式的使用 if  条件then Commandelse Commandfi                              别忘了这个结尾 If语句忘了结尾fites ...

  3. Shell 编程 循环语句

    本篇主要写一些shell脚本循环语句的使用. for 循环 指定次数 #!/bin/bash for ((i=1;i<=10;i++)) do echo $i done [root@localh ...

  4. Shell 编程 case语句

    本篇主要写一些shell脚本case语句的使用. 字符判断 #!/bin/bash read -p "请输入一个字符:" char case $char in [a-z]|[A-Z ...

  5. Shell 编程 条件语句

    本篇主要写一些shell脚本条件语句的使用. 条件测试 test 条件表达式 [ 条件表达式 ] 文件测试 -d:测试是否为目录(Directory). -e:测试文件或目录是否存在(Exist). ...

  6. shell编程——if语句 if -z -n -f -eq -ne -lt

    if  条件then Commandelse Commandfi                              别忘了这个结尾 If语句忘了结尾fitest.sh: line 14: sy ...

  7. shell编程——if语句

    if 语句格式 if  条件 then  Command else  Command fi                              别忘了这个结尾 If语句忘了结尾fi test.s ...

  8. Linux Shell编程case语句

    http://blog.csdn.net/dreamtdp/article/details/8048720 case语句适用于需要进行多重分支的应用情况. case分支语句的格式如下: case $变 ...

  9. 1.Shell编程循环语句(if 、while、 until)

    循环语句 for循环语句 读取不同的变量值,用来逐个执行同一组命令 格式: for 变量名 in 取值列表 do 命令序列 done 示例:批量创建用户并设置密码 [root@localhost da ...

随机推荐

  1. LG4782 「模板」2-SAT问题 2-SAT

    问题描述 LG4782 题解 对于一个限制条件,建边如下: 如果\(x,-x\)在同一个强联通分量里,则不行,否则可以 构造方案:输出\(bel_i<bel_{i+n}\) \(\mathrm{ ...

  2. Linux引导过程与服务控制

    一:系统引导流程: 开机自检(BIOS)-->MBR引导-->GRUB菜单-->加载内核(kernel)-->init进程初始化  二:系统引导级别: 0 poweroff.t ...

  3. [LeetCode] 212. Word Search II 词语搜索之二

    Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...

  4. Note | PyTorch官方教程学习笔记

    目录 1. 快速入门PYTORCH 1.1. 什么是PyTorch 1.1.1. 基础概念 1.1.2. 与NumPy之间的桥梁 1.2. Autograd: Automatic Differenti ...

  5. 1,[VS入门教程] 使用Visual Studio写c语言 入门与技巧精品文~~~~下载安装篇

    Microsoft Visual Studio是微软(俗称巨硬)公司出品的强大IDE(Integrated Development Environment 集成开发环境),功能强大齐全,界面舒服之类的 ...

  6. idea找不到tomcat,找不到Tomcat server

    打开settings  添加即可 如果再没有,可能需要先安装timcat插件

  7. CentOS7 Hbase 安装(完全分布式)

    安装前准备 hadoop安装 zookeeper安装 安装步骤 1.下载 $ wget http://mirror.bit.edu.cn/apache/hbase/2.0.5/hbase-2.0.5- ...

  8. 使用nodemon提高nodejs调试效率

    1.安装 nodemon 直接用npm安装既可,键入命令: npm -g install nodemon .如果不行,检查电脑有没有联网,联网后输入 sudo npm -g install nodem ...

  9. java知识体系(自我学习中)

    java自我学习知识体系

  10. WPF XAML Trigger中使用动画后 动画对象冻结的处理办法

    在编写XAML时 在Trigger中使用动画,在动画之后,动画对象就会被冻结,无法被其他动画或者属性改变. 处理办法有: 1 使用附加属性来添加动画 public static readonly De ...