执行脚本: sh login.sh user,其中user为第一个参数

如下所示,如果用户‘user’登录,'who | grep "$1"'为true,until循环结束,程序继续执行,输出 “***** user has just logged in *****”信息。

如果用户‘user’没有登录,屏幕每隔60秒打印一次“ok”。

$1表示程序的第一个参数

 # login.sh  
1 #!/bin/bash until who | grep "$1" > /dev/null
do
sleep 60
    echo 'ok'
done # Now ring the bell and announce the unexpected user. echo -e '\a'
echo "***** $1 has just logged in *****" exit

linux的shell的until循环举例说明的更多相关文章

  1. linux shell条件与循环举例

    1. if/else 语句 语法: if condition; then commands;elif condition; then commands;else commands;fi 示例:需求:脚 ...

  2. Linux - 简明Shell编程06 - 循环语句(Loop)

    脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash # for循环 for fil ...

  3. Linux下Shell的for循环语句

    第一类:数字性循环-----------------------------for1-1.sh #!/bin/bash ;i<=;i++)); do + ); done ------------ ...

  4. Linux centosVMware shell编程 for循环、while循环、break跳出循环、continue结束本次循环、exit退出整个脚本

    一.for循环 语法:for 变量名 in 条件; do …; done 案例1 #!/bin/bash sum=0 for i in `seq 1 100` do sum=$[$sum+$i] ec ...

  5. Linux shell编程 4 ---- shell中的循环

    1 for循环 1 for语句的结构 for variable in values; do statement done 2 for循环通常是用来处理一组值,这组值可以是任意的字符串的集合 3 for ...

  6. Linux和Shell教程

    文档资料参考: 参考:http://www.runoob.com/linux/linux-tutorial.html 软件下载参考: centos 下载地址:https://www.centos.or ...

  7. linux中用shell获取昨天、明天或多天前的日期

    linux中用shell获取昨天.明天或多天前的日期 时间 -- :: BlogJava-专家区 原文 http://www.blogjava.net/xzclog/archive/2015/12/0 ...

  8. linux中用shell获取时间,日期

    linux中用shell获取昨天.明天或多天前的日期:在Linux中对man date -d 参数说的比较模糊,以下举例进一步说明:# -d, --date=STRING display time d ...

  9. Linux Bash Shell 快速入门

    BASH 的基本语法 最简单的例子 —— Hello World! 关于输入.输出和错误输出 BASH 中对变量的规定(与 C 语言的异同) BASH 中的基本流程控制语法 函数的使用 2.1     ...

随机推荐

  1. shell 数值比较和字符串比较

    1. 数值比较 -eq        是否相等(equal) -gt         是否大于(greater than) -ge       是否大于等于(greater and equal tha ...

  2. Linux之vi(vim)编辑器

    命令行模式:默认进来就是命令行模式 ,可以使用很多命令:比如i . a . o i:光标前面输入内容 a:光标的下一位字符开始输入内容 o:光标的下一行开始输入内容 编辑模式: 退出编辑模式:键盘上e ...

  3. Python list 增加/插入元素的说明

    http://blog.csdn.net/cnmilan/article/details/9259343 在Python中append 用来向 list 的末尾追加单个元素,如果增加的元素是一个lis ...

  4. Sybase PowerDesigner 16.5注册码

    Sybase PowerDesigner16.5安装之后一段时间就会过期,破解办法是:将pdflm16.dll文件覆盖原来的即可. pdflm16.dll文件下载地址:链接:https://pan.b ...

  5. Python 模块学习(一)

    一.时间模块 import time # 模块调用语句 注意:模块级导入一般放在文件顶部 import datetime print(time.time()) # 1550411181.441547: ...

  6. LeetCode(171) Excel Sheet Column Number

    题目 Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, re ...

  7. LeetCode(18)4Sum

    题目 Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = ...

  8. 用python写自定义模板

    模板语法有点像php !/usr/bin/env python """ #demo.py.html <html> <?py include head.p ...

  9. 大数据学习——hive的sql练习

    1新建一个数据库 create database db3; 2创建一个外部表 --外部表建表语句示例: create external table student_ext(Sno int,Sname ...

  10. 大数据学习——装私服nexus

    (一)安装 解压之后 进入bin文件夹下 复制路径 D:\software\nexus-2.12.0-01-bundle\nexus-2.12.0-01\bin 进入命令行窗口输入以下命令,安装成功 ...