执行脚本: 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. 总结vue2.0 配置的实例方法

    总结vue2.0 配置的实例方法 http://www.php.cn/js-tutorial-369603.html

  2. app自动化配置信息

    caps={    "platformName":"Android",#平台名称    "platformVersion":"6. ...

  3. node.js中使用Redis

    服务端: 启动Redis服务: redis-server 客户端: 1.安装Redis        npm install redis --save 2.redisTest.js文件 //引入red ...

  4. PHP06 流程控制

    学习要点 选择结构 循环结构 学习目标 掌握PHP的选择结构 掌握PHP的循环结构 流程控制概述 程序 程序:一系列计算机指令的集合. 编程语言:开发程序的工具. 程序执行结构 计算机程序有三种基本执 ...

  5. lspci详解分析

    lspci详解分析 一.PCI简介 PCI是一种外设总线规范.我们先来看一下什么是总线:总线是一种传输信号的路径或信道.典型情况是,总线是连接于一个或多个导体的电气连线,总 线上连接的所有设备可在同一 ...

  6. js模块化入门与commonjs解析与应用

    JS模块化的基本原理 commonjs规范 commonjs在前端模块化中的基本使用 AMD与CMD规范剖析博客链接 一.JS模块化基本原理 在JS没有提出来模块化的时候,开发JS项目比较简单,同时也 ...

  7. 监控java进程是否正常运行

    @echo off set _task=java.exe :checkstart for /f "tokens=1" %%n in ('tasklist ^| find " ...

  8. django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module

    pip3 install mysqlclient try again python manage.py makemigrations python manage.py migrate

  9. WEB 前端模块化,读文笔记

    文章链接 WEB 前端模块化都有什么? 知识点 根据平台划分 浏览器 AMD.CMD 存在网络瓶颈,使用异步加载 非浏览器 CommonJS 直接操作 IO,同步加载 浏览器 AMD 依赖前置 req ...

  10. nodejs实现网站数据的爬取

    // 引入https模块,由于我们爬取的网站采用的是https协议 const https = require('https'); // 引入cheerio模块,使用这个模块可以将爬取的网页源代码进行 ...