小sh脚本出错

时间:2011-07-22 13:32:17

标签: linux dialog sh

当我运行程序并单击“是”时会抛出错误:

/home/zygis/tools/script: 26: Syntax error: ")" unexpected (expecting ";;")

代码:

DIALOG=${DIALOG=dialog}

$DIALOG --title " My first dialog" --clear \
        --yesno "You really want to run this program?" 10 30

case $? in
  0)
    if [ "$1" = "start" ];
    then
            echo "Enter OS: ";
            read OS
            echo OS
            python /home/zygis/tools/dj.py $OS
    else
        if [ "$1" = "uprint" ];
        then
            echo "usage: {start}";
            echo "example: (./boot start)";
        else
            echo "Invalid choice";
            echo "To usage use uprint";
        fi
    fi
  1)
    echo "No chosen.";
  255)
    echo "ESC pressed.";
esac

3 个答案:

答案 0 :(得分:3)

case/esac的每个案例都必须由;;终止。 See the man page...

case $? in
  0)
    if [ "$1" = "start" ];
    then
            echo "Enter OS: ";
            read OS
            echo OS
            python /home/zygis/tools/dj.py $OS
    else
        if [ "$1" = "uprint" ];
        then
            echo "usage: {start}";
            echo "example: (./boot start)";
        else
            echo "Invalid choice";
            echo "To usage use uprint";
        fi
    fi
    # Terminate.....
    ;;
  1)
    echo "No chosen.";
    # Terminate.....
    ;;
  255)
    echo "ESC pressed.";
    # Terminate.....
    ;;
esac

答案 1 :(得分:1)

你必须使用“;;”结束你的案件。

case $? in
    0)
        echo "case 0";;
    1)
        echo "case 1";;
esac

答案 2 :(得分:1)

使用两个分号;;结束每种情况,即:

case ...
1) some_command ;;
2) other command ;;
esac