歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> shell腳本中的“請按任意鍵繼續”

shell腳本中的“請按任意鍵繼續”

日期:2017/3/1 9:59:54   编辑: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 ""

來看下執行效果:

就是這個效果了。

Copyright © Linux教程網 All Rights Reserved