如何将break语句置于korn脚本

时间:2017-02-02 10:03:28

标签: shell ksh

我正在编写一个korn脚本来处理一些固定/用户提供的输入。我无法运行此脚本,因为我收到语法错误 `)'意外 。我在想这是因为我在if语句中使用了一个break,其中if在switch案例中。我上周刚拿起脚本,非常感谢任何帮助。 P.S使用korn脚本是有原因的。

  #!/usr/bin/ksh93

  typeset -A fileset_list               #fileset_list is associative

  fileset_list=([All filesets]="A B C D E"
           [A]=AA
           [B]=BB
           [C]="CC CCC CCCC CCCC"
           [D]=DD
           [E]="EE EEE EEEE EEEE EEEEE"
          )

        fileset="All filesets"
        echo "Recent update has found following unsupported filesets on the system:\n${fileset_list["All filesets"]}"
        echo "Do you want to delete all the listed filesets along with their dependencies Y/N"
        while true; do
                read yn
                case $yn in
                [Yy]* )
                        set -A delete_list ${fileset_list["All filesets"]}
                        uninstall_fun
                        break;;

                [Nn]* )
                        echo "Do you want to delete the partial list Y/N"
                        while true; do
                                read y_n
                                case $y_n in
                                [Yy]* ) echo "Enter the space separated filesets from the above list for deletion"
                                        read user_list
                                        echo "You have entered $user_list\nIs the list correct Y/N"
                                        read selection

                                        if [[ $selection == [Yy]* ]]
                                        then
                                                set -A delete_list $user_list
                                                uninstall_fun
                                                break;; #<<<<ISSUE
                                        else
                                                echo "Do you want to re-enter list Y/N" #<<<<<need this to go back and read y_n
                                        fi

                        #               break;;
                                [Nn]* )
                                        break;;

                                    * ) echo "Please answer yes(y) or no(n).";;

                                esac
                        done

                        break;;
                * ) echo "Please answer yes(y) or no(n).";;
                esac
        done

uninstall_fun(){
 echo "In uninstall_fun"
}

1 个答案:

答案 0 :(得分:1)

;;块在每个case块的末尾使用。你在if语句的中间有一个,但case块还没有完成。
break;; # <<<<ISSUE行应为break # without ;;
# break;;应为;;

[Yy]* ) echo "Enter the space separated filesets from the above list for deletion"
        read user_list
        echo "You have entered $user_list\nIs the list correct Y/N"
        read selection

        if [[ $selection == [Yy]* ]]
        then
           set -A delete_list $user_list
           uninstall_fun
           break # Without ;;
        else
           echo "Do you want to re-enter list Y/N" #<<<<<need this to go back and read y_n
        fi

        ;; # Needed here
[Nn]* )