실행 일시 정지 및 사용자 입력 대기

스크립트를 작성 중이며 문제가 있습니다. 실행을 일시 중지하고 사용자 입력을 기다립니다. 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!!!!

메인 메뉴 기능에서 -n 1 -p “text goes here”항목을 볼 수 있습니다. 우분투에 따르면 문제가 발생하는 곳입니다. 누군가 무엇이 잘못되고 있는지 말해 줄 수 있습니까? 감사!



답변

해야한다:

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

필요는 넣어 n, 후 플래그를 그 후에 실행 읽어 말하고 그대로 N 개의 문자를 입력, 전체 라인을 기다리지 않습니다. 확인 help read자세한 내용은이를 .