执行函数后如何显示菜单选项?

执行函数后如何显示菜单选项?

我有以下脚本:

while true; do
  echo "# Available tests:"
  PS3="Please select which test must be performed [1-9]: "
  options=("CPU Stress Test (local)" "Memory Stress Test (local)" "Intensive Random Write I/O on disks (5 min) (local)" "Intensive Random Read I/O on disks (5 min) (local)" "Intensive Read I/O on disks (5 min) (local)" "Intensive Write on disks I/O (5 min) (local)" "Cache Read Capability (local)" "Measure Network Bandwidth (Between nodes)" "Quit")
  select opt in "${options[@]}"
  do
    case $opt in
    "CPU Stress Test (local)")
            sleep 2
            cpu
            cleanup
    ;;
    "Memory Stress Test (local)")
            sleep 2
            memory
            cleanup
    ;;
    "Intensive Random Write I/O on disks (5 min) (local)")
            prereq
            cslist
            randwrite
            sleep 2
    ;;
    "Intensive Random Read I/O on disks (5 min) (local)")
            sleep 2
    ;;
    "Intensive Read I/O on disks (5 min) (local)")
            sleep 2
    ;;
    "Intensive Write on disks I/O (5 min) (local)")
            sleep 2
    ;;
    "Cache Read Capability (local)")
            sleep 2
    ;;
    "Measure Network Bandwidth (Between nodes)")
            sleep 2
    ;;
    "Quit")
            echo "All right, bye bye! :)"
            echo "Exiting..."
            sleep 2
            exit 1
    ;;
    *) echo "Invalid option ($REPLY)";;
    esac
  done
done

例如,如果我选择选项 1 CPU Stress Test (local),它会成功执行,但最后只出现我的PS3问题,而没有来自 的选项select opt in...,有人可以帮助我吗?

谢谢

答案1

selectbreak在执行命令之前构造不会退出

因此,在每个操作完成后,使用break命令:

    case $opt in
    "CPU Stress Test (local)")
            sleep 2
            cpu
            cleanup
            break
    ...

相关内容