我的菜单程序需要帮助

我的菜单程序需要帮助

我的脚本有问题,执行时选择 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

相关内容