go4321 发表于 2018-8-19 09:54:51

shell脚本中的“请按任意键继续”

  在Windows的bat脚本中,我们插入pause关键字就可以实现“请按任意键继续”的功能,下面我们来看看Linux下Shell脚本中怎么实现。
  脚本代码:any.sh
  


[*]#!/bin/bash
[*]
[*]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
[*]}
[*]
[*]echo "Press any key to continue!"
[*]char=`get_char`
[*]
[*]echo ""
[*]echo "Hello!"
[*]echo "http://cto.luxiaok.com"
[*]echo ""
  

  来看下执行效果:

  就是这个效果了。


页: [1]
查看完整版本: shell脚本中的“请按任意键继续”