我参考了这个文章:用shell实现bat的pause
http://linux-wiki.cn/wiki/zh-hans/%E7%94%A8shell%E5%AE%9E%E7%8E%B0bat%E7%9A%84pause
文中提示:
#! /bin/bash function pause(){ read -n 1 -p "$*" INP if [ $INP != ‘‘ ] ; then echo -ne ‘\b \n‘ fi } #使用时: pause ‘Press any key to continue...‘
仍存有的问题:
我在此基础上:
仍存有的问题:
最终代码:
#! /bin/bash function pause(){ echo ‘Press any key to continue...‘ read -n 1 -p "$*" str_inp if [ -z "$str_inp" ];then str_inp=1 fi #echo "+$str_inp+" if [ $str_inp != ‘‘ ] ; then echo -ne ‘\b \n‘ fi } #使用时:不要用方向键 #pause pause
原文:https://www.cnblogs.com/date/p/10497018.html