zoukankan      html  css  js  c++  java
  • shell脚本使用技巧4--读取字符,重复执行

    ls | cat -n > out.txt 给输出的信息加行号并导出到out.txt

    利用shell生成一个独立的进程

    pwd;

    (cd /bin; ls);

    pwd;

    开启一个子shell,不会影响到当前shell的路径;

    1.从输入读取n个字符存入变量variable_name

    read -n numer_of_chars variable_name

    ex:

    read -n 3 var 

    echo $var

    (2)用无回显的方式读取密码

    read -s var 

    (3)显示提示信息

    read -p "enter input:" var

    (4)在特定的时间内读取输入

    read -t timeout var

    ex:

    read -t 2 var

    (5)用特定的定界符作为输入行的结束

    read -d delim_char var

    ex:

    read -d ":" var

    重复执行命令函数:

    repeat()

    {

      while true

      do

        $@ && return

      done

    }

    或者放入shell的rc文件,便于使用:

    repeat() {while true;do $@ && return; done}


    repeat() {while :;do $@ && return; done}

    修改间隔时间后再次执行,默认会不断执行:
    repeat() {while :; do $@ && return ; sleep 30; done}

    example:
      repeat wget-c http://www.example.com/software.tar.gz

    怕什么真理无穷,进一寸有一寸的欢喜。---胡适
  • 相关阅读:
    Keep at Most 100 Characters
    Larry and Inversions
    计算指数
    简单题
    重要的话说三遍
    I Love GPLT
    猜数字
    打印沙漏
    多态性(polymorphism),封装性(encapsulation),内聚(cohesion)以及耦合(coupling)的基本概念
    Hibernate面试题
  • 原文地址:https://www.cnblogs.com/hujianglang/p/6978758.html
Copyright © 2011-2022 走看看