메뉴 프로그램에 도움이 필요합니다

메뉴 프로그램에 도움이 필요합니다

내 스크립트에 문제가 있습니다. 선택 2와 3을 실행할 때 아무 것도 표시되지 않습니다.

#!/bin/bash
while true
 do
  clear
  echo "========================"
  echo "Menu ----"
  echo "========================"
  echo "enter 1 to print home directory,Files,user id,login shell and date: "
  echo "enter 2 to generate 5 random number betweeon 0 to 100: "
  echo "press 3 to print the min and max of the generated numbers: "
  echo "press 4 to exit the program: "
  echo -e "\n"
  echo -e "Enter your selection \c"
  read answer
  case "$answer" in
   1) $USER ; echo "Press a key. . ." ; read ;
      echo "Files in `pwd`" ; ls -l ; echo "Press a key. . ." ; read
      $UID ; echo "Press a key. . ." ; read ;
      echo "Today is `date` , press a key. . ." ; read ;;
   2) echo, shuf -i 0-100 -n 5 ;;
   3) shuf -i MIN-MAX -n COUNT ::
   4) exit;;

 esac
done

편집 : 해결되었습니다 :)

답변1

select메뉴에 내장된 명령문을 사용하세요.

#!/usr/bin/env bash
choices=(
    "print home directory,Files,user id,login shell and date"
    "generate 5 random number betweeon 0 to 100"
    "print the min and max of the generated numbers"
    "exit the program"
)
PS3='Enter your selection: '

while true; do
    clear
    echo "========================"
    echo "Menu ----"
    echo "========================"
    select answer in "${choices[@]}"; do

        # if the user entered a valid selection: 
        # - the "answer" variable will contain the _text_ of the selection,
        # - the "REPLY" variable will contain the selection _number_
        case "$REPLY" in
            1) echo "do stuff for $answer ..." ;;
            2) echo "do stuff for $answer ..." ;;
            3) echo "do stuff for $answer ..." ;;
            4) exit ;;
        esac

        # we loop within select until a valid selection is entered.
        [[ -n "$answer" ]] && break
    done
    read -p "Hit enter to continue ..."
done

관련 정보