首页 > 解决方案 > If-Statement 疯了(还是我?)

问题描述

这是我的 bash 脚本的参数之一。但似乎有什么不对劲。

bash 脚本:

case "${1}" in
--api )
        if ( "${2}" == "US" ); then
            sparkEndpoint="https://api.sparkpost.com/api/v1/transmissions"
            shift
        elif ( "${2}" == "EU" ); then
            sparkEndpoint="https://api.eu.sparkpost.com/api/v1/transmissions"
            shift
        else
            echo -e ${parameterNotSpecified}
            echo -e ${usageApi}
            break
        fi
        shift
    ;; [...]

控制台输出:

./fn_sendmail.sh --api EU
./fn_sendmail.sh: Zeile 95: EU: Kommando nicht gefunden.
./fn_sendmail.sh: Zeile 98: EU: Kommando nicht gefunden.
You called an option but didn't specified it! Usage of --api
--api [eu,us]
        Description: Sets the API endpoint for Sparkpost
        Necessary: No
        Default: EU

标签: bash

解决方案


你可能需要

shift 2

删除 the--api location (US/EU)。


推荐阅读