メニュープログラムに助けが必要です

メニュープログラムに助けが必要です

私のスクリプトに問題があります。選択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

おすすめ記事