0

尝试在终端中运行此命令时:

gerard@yoda ~$ Sources/Scripts/ultimate.sh -u -typecount -std /usr/bin py
Sources/Scripts/ultimate.sh: line 28: syntax error near unexpected token `elif'
Sources/Scripts/ultimate.sh: line 28: `elif [ $1 = "-h" ];'

这是脚本的来源:

#!/bin/bash

## $1 = Mode(u/h) ; $2 = Command(?) ; $3+ = Params

if [ $1 = "-u" ];
    if [ $2 = "-typecount" ];
    then
        if [ $3 = "-std" ];
        then
            find $4 -maxdepth 1 -iname *.$5 | wc -l
        elif [ $3 = "-ext" ];
        then
            find $5 -maxdepth $4 -iname *.$6 | wc -l
        else
            echo 'use option -std for single-dir'
            echo 'or option -def for recusive with custom depth'
            echo 'filetype should be defined  type  instead of .type'
        fi
    elif [ $2 = "-prep" ];
    then
        sed -i 's/^/$3/' $4
    elif [ $2 = "-app" ];
    then
        sed -i 's/$/$3/' $4
    else
        echo 'No command specified/Command not found'
    fi
elif [ $1 = "-h" ];
then
    if [ $2 = "-typecount" ];
    then
        echo 'for -std: [location] [type]'
        echo 'for -ext: [depth] [location] [type]'
    elif [ $2 = "-prep" ];
    then
        echo '[text] [file]'
    elif [$2 = "-app" ];
    then
        echo '[text] [file]'
    else
        echo 'No command specified/Command not found'
else
    echo 'No mode specified/Wrong mode'
fi

语法对我来说似乎是正确的,并且具有相同 elif 构造的脚本的更简单版本可以正常工作。我做错什么了?(需要的函数解析完成后脚本需要退出)

4

1 回答 1

3

在顶部,第一个之后没有then关键字if

if [ $1 = "-u" ];
**then**
    if [ $2 = "-typecount" ];

您还缺少fi接近底部的内容:

    else
        echo 'No command specified/Command not found'
    **fi**
else
于 2013-01-06T20:42:28.383 回答