zoukankan      html  css  js  c++  java
  • 在shell脚本中添加暂停,按任意键继续

    分析一个复杂脚本的时候,有时候需要加点暂停,分段来看,比较清晰

    于是参考了一些实现,目前自己用的是这样子的

    #add for debug by zqb
    
    function get_char()
    {
      SAVEDSTTY=`stty -g`
      stty -echo
      stty cbreak
      dd if=/dev/tty bs=1 count=1 2> /dev/null
      stty -raw
      stty echo
      stty $SAVEDSTTY
    }
    
    enable_pause=1
    function pause()
    {
      if [ "x$1" != "x" ] ;then
        echo $1
      fi
      if [ $enable_pause -eq 1 ];then
        echo "Press any key to continue!"
      char=`get_char`
      fi
    }

    然后在需要暂停的地方,调用pause函数,参数是提示信息

    比如

    xxx
    pause "xxx ok"
    yyy
    pause "yyy ok"
    zzz

    为了方便调试,加了个开关变量
    enable_pause=1,改成0可以取消添加的暂停


    本文链接 http://www.cnblogs.com/zqb-all/p/6296638.html
  • 相关阅读:
    bzoj 1053
    bzoj 1004 组合
    字符串哈希
    bzoj 1015 并查集
    bzoj 1003 最短路+dp
    HDU 4352 数位dp
    bzoj 1879 状压dp
    codeforces 55D 数位dp
    Codeforces 830B
    组合计数 && Stirling数
  • 原文地址:https://www.cnblogs.com/zqb-all/p/6296638.html
Copyright © 2011-2022 走看看