break:仅在'for',`while'或`until'循环中有意义

时间:2014-02-20 20:03:15

标签: bash dialog

任何人都可以帮我解决这个问题

我的bash是

#!/bin/bash
#Setup Scripts Project v1.0
#By me
#===============================================



     dialog --backtitle "Setup Scripts " \
     --title "[Main Menu]" \
     --menu "You can use the UP/DOWN arrow keys, Or the number keys 1-9 to choose an option.\n\
    Choose the option" 18 70 8 \
        Setup "Start Setup And Secure this Server" \
        Nginx_Setup "Install Nginx" \
        Anti_MaleWare "Install Anti-MaleWare" \
        Softaculous "Install Softaculous" \
        ModSec "Install ModSecurity" \
        OpsView "Add OpsView Agent" \
        External_Backup "Add This Server To External Backup" \
        Check_Backup "Check Backup Configration" \

menuitem=$(<"${INPUT}")

#Select Option

  case $menuitem in
 Setup) setup;;
 Nginx_Setup) nginx;;
 Anti-MaleWare) anti-maleware;;
 Softaculous) Softaculous;;
 ModSec) modsec;;
 OpsView) opsview;;
 External_Backup) externalbackup;;
 Check_Backup) configbackup;;
     Exit) echo "" ; echo "" ;  break;;
      *) echo "" ; echo "" ; break;;
  esac

错误

./main_menu.sh: line 19: : No such file or directory

./main_menu.sh: line 32: break: only meaningful in a `for', `while', or `until' loop

我需要解决此错误当我按任何此操作从其他bash脚本执行此操作

最诚挚的问候,

1 个答案:

答案 0 :(得分:1)

我找到了答案here。有一个疯狂的重定向序列交换stdout和stderr,以便菜单可以显示在屏幕上,但可以通过命令替换捕获答案:

我清理了很多代码,使用数组来保存代码。

#!/bin/bash

options=( 
    --backtitle "Setup Scripts " 
    --title "[Main Menu]" 
    --menu "You can use the UP/DOWN arrow keys, Or the number keys 1-9 to choose an option.
Choose the option" 18 70 8 
)

choices=(
    Setup           "Start Setup And Secure this Server" 
    Nginx_Setup     "Install Nginx" 
    Anti_MaleWare   "Install Anti-MaleWare" 
    Softaculous     "Install Softaculous" 
    ModSec          "Install ModSecurity" 
    OpsView         "Add OpsView Agent" 
    External_Backup "Add This Server To External Backup" 
    Check_Backup    "Check Backup Configration" 
)

menuitem=$( dialog "${options[@]}" "${choices[@]}" 3>&1 1>&2 2>&3 3>&- )

case $menuitem in
    Setup)           setup ;;
    Nginx_Setup)     nginx ;;
    Anti-MaleWare)   anti-maleware ;;
    Softaculous)     Softaculous ;;
    ModSec)          modsec ;;
    OpsView)         opsview ;;
    External_Backup) externalbackup ;;
    Check_Backup)    configbackup ;;
    "")              clear ;;
esac