如何在linux中检查是否大于条件?

时间:2014-02-28 00:18:35

标签: linux string

如果tag_len大于18tag_len19且标记不以“A”结尾, 我想将标签剪切为长度为18。

我尝试了几个选项,但这样做不正常。 你现在能告诉我怎样才能做到这一点吗?


#officail daily release TAG check

official_tag_len=18

export tag_len=`expr length $TAG`

if (($tag_len > $official_tag_len))

then

    echo "$TAG length is greater than $official_tag_len"
    if (($tag_len == ($official_tag_len+1))) && (($TAG == *A))
    then
        echo $TAG is an AM daily tag
    else
        echo $TAG is a temporary tag. reset to daily tag
        export TAG=$($TAG:0:$official_tag_len)
    fi
fi

更新

最后的错误消息是

e7e10_preqe2:0:18:找不到命令

我编辑代码“export TAG = $($ TAG:0:$ official_tag_len)” 提到Extract substring in Bash

还有一件事, 起初我写了[[而不是((如果条件但命令未找到错误发生在[[line。

通常,我在if条件中使用了[]表达式。 有没有特例?

1 个答案:

答案 0 :(得分:1)

问题设置有点难以理解,但我认为这会按照bash的方式运行。你没有为这个问题指定解释器。

我已经自由地将“TAG”作为输入参数(TAG=$1,并使用命令wc计算它的长度)。

我已将所有if语句替换为使用方括号,并使用关键字-gt(大于)进行比较(对lt使用<,并{ {1}} eq。这些用于数字比较。

==