我有一个正在编写的脚本,但有一个问题:我想暂停执行并等待用户输入。我以为我在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“文本在此处”条目。根据ubuntu,这就是我遇到的问题。有人可以告诉我出什么事了吗?谢谢!
#!/usr/bin/env bash
或#!/bin/bash
。