暂停执行并等待用户输入

我有一个脚本,我正在制作它有一个问题:我想暂停执行并等待用户输入。 我以为我使用read -p -n 1 $foo命令,但系统遇到了这个命令的问题。 这是我目前的脚本:

 #!/bin/sh # Ititialization mainmenu () { echo "Press 1 to update your system" echo "Press 2 to install samba" echo "Press 3 to install vsFTPd" echo "Press 4 to install the current version of Webmin" echo "Press 5 to configure samba for Active Directory" echo "Press x to exit the script" read -n 1 -p "Input Selection:" mainmenuinput if [ "$mainmenuinput" = "1" ]; then updatesystem elif [ "$mainmenuinput" = "2" ]; then installsamba elif [ "$mainmenuinput" = "3" ]; then installvsftpd elif [ "$mainmenuinput" = "4" ]; then installwebmin elif [ "$mainmenuinput" = "5" ]; then configuresambaforactivedirectory elif [ "$mainmenuinput" = "x" ];then quitprogram elif [ "$mainmenuinput" = "X" ];then quitprogram else echo "You have entered an invallid selection!" echo "Please try again!" echo "" echo "Press any key to continue..." read -n 1 clear mainmenu fi } # This builds the main menu and routs the user to the function selected. mainmenu # This executes the main menu function. # Let the fun begin!!!! WOOT WOOT!!!! 

你可能会注意到在mainmenu函数中读取-n 1 -p“text goes here”条目。 根据ubuntu,这就是我遇到问题的地方。 有人能告诉我出了什么问题吗? 谢谢!

应该:

 read -n 1 -p "Input Selection:" mainmenuinput 

需要把n标志放在后面,因为这是在输入N个字符后告诉读执行,不要等待整行。 查看help read和详细信息 。