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


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

脚本代码:any.sh

  1. #!/bin/bash
  2. get_char()
  3. {
  4. SAVEDSTTY=`stty -g`
  5. stty -echo
  6. stty cbreak
  7. dd if=/dev/tty bs=1 count=1 2> /dev/null
  8. stty -raw
  9. stty echo
  10. stty $SAVEDSTTY
  11. }
  12. echo "Press any key to continue!"
  13. char=`get_char`
  14. echo ""
  15. echo "Hello!"
  16. echo "http://cto.luxiaok.com"
  17. echo ""

来看下执行效果:

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

就是这个效果了。

相关内容