将 shell 脚本转换为 bash 脚本

将 shell 脚本转换为 bash 脚本

有人可以帮我将这个 shell 脚本转换为 bash 脚本吗?

我的 shell 脚本如下

#!/bin/bash

IN="ifa_in_B2C=ifa_inB2C;ifa_in_ERP_Soap=ifa_inERP;sm=sm_main;tp=tp_main;trp=trp_main;usr=usr_main;wl=wl_main;pe_notification_email=pe_email;pe_notification_sms=pe_sms;pe_group_calc=pe_group;ifa_out_sms=ifa_outSMS;ifa_out_email=ifa_outEmail;ifa_out_oxiB2C=ifa_outOxi;ifa_out_OMTS=ifa_outOMTS;log=log_main;sys=sys_main;ifa_sys=ifa_sys;sm_sys=sm_sys;sp=sp_main;usr_sys=usr_sys;cache_reload=cache_reload"

export GOPATH=C:/Users/user/Desktop/nxtxn-b2c
export PATH=$PATH:C:/Users/user/Desktop/nxtxn-b2c/srcC:/Users/user/Documents/nxtxn-b2c/src:C:/Go/bin
arr=$(echo $IN | tr ";" "\n")
echo "No of Arguments Passed is "$#
if [ "$#" -gt "2" ] || [ "$#" == "2" ]; then
    DATE=`date +%Y-%m-%d:%H:%M:%S`
    BUILD_ARG=""
    echo $DATE
    if [ "$3" == "buildversion" ]; then
        echo "ENTER the Version no"
        read VERSION_NO
        echo "ENTER Version Description"
        read VERSION_DESP
        if [ "$VERSION_NO" == "" ]; then
            $BUILD_ARG=""
        else 
            TEMP="\"-X main.version $VERSION_NO -X main.version_date $DATE -X main.version_desc $VERSION_DESP\""
            echo $TEMP
            BUILD_ARG="-ldflags "
            BUILD_ARG=$BUILD_ARG$TEMP
        fi
    else
        echo "Wrong 3rd argument: Use buildversion to create version tags"
    fi
    echo "Build Arguments : "$BUILD_ARG

    echo "METHOD:$1 SUBSYS:$2"
    echo "GOPATH : $GOPATH"
    for subsys in $arr
    do
        IFS='=' read -a arr_tmp <<< "$subsys"
        echo "%%%%%%%%%%%%%%%%%%%%%%%%%  START   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
        echo "SUBSYS: ${arr_tmp[0]}"
        subsys_pkg=${arr_tmp[0]}"_pkg"
        echo "$subsys_pkg"
        subsys_main=${arr_tmp[0]}"_main"
        if [[ ${arr_tmp[0]} != pe* ]] ; then
            main_path="$GOPATH/src/${arr_tmp[0]}/$subsys_main"
        else
            main_path="$GOPATH/src/pe/${arr_tmp[0]}/$subsys_main"
        fi

        if [[ ${arr_tmp[0]} != pe* ]] ; then
            cd "$GOPATH/src/${arr_tmp[0]}/$subsys_pkg"
        else
            cd "$GOPATH/src/pe/${arr_tmp[0]}/$subsys_pkg"
        fi
        if [ "$1" == "build" ]; then
            if [ "$2" == "all" ]; then
                cd $main_path
                echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
                eval go install -v -x $BUILD_ARG
                ret_cmd=$?
                error_msg="ERROR : Failed to run the build command!"
                if [ $ret_cmd != 0 ]; then
                   echo "$error_msg"
                   exit;
                fi
                mv $GOPATH/bin/${arr_tmp[0]}"_main" $GOPATH/bin/${arr_tmp[1]}
                echo "BUILT and INSTALLED : ${arr_tmp[0]}"
            elif [ "$2" == ${arr_tmp[0]} ]; then
                cd $main_path
                echo "***********%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%***********"
                eval go install -v -x $BUILD_ARG
                ret_cmd=$?
                error_msg="ERROR : Failed to run the build command!"
                if [ $ret_cmd != 0 ]; then
                    echo "$error_msg"
                    exit;
                fi
                mv $GOPATH/bin/${arr_tmp[0]}"_main" $GOPATH/bin/${arr_tmp[1]}
                echo "BUILT and INSTALLED : ${arr_tmp[0]}"
                break
                78,1-8        40%
            fi
        elif [ $1 == "cleanbuild" ]; then
           if [ $2 == "all" ]; then
               echo "**********************    CLEAN      ***************************"
               cd $main_path
               go clean -i -x
               echo "****************************************************************"
               eval go install -v -x $BUILD_ARG
               ret_cmd=$?
               error_msg="ERROR : Failed to run the build command!"
               if [ $ret_cmd != 0 ]; then
                   echo "$error_msg"
                   exit;
               fi
               mv $GOPATH/bin/${arr_tmp[0]}"_main" $GOPATH/bin/${arr_tmp[1]}
               #eval go install -v -x $BUILD_ARG
               echo "CLEANED and INSTALLED : ${arr_tmp[0]}"
               elif [ $2 == ${arr_tmp[0]} ]; then
                   echo "**********************    CLEAN      ***************************"
                   cd $main_path
                   go clean -i -x
                   echo "%%%%%%%*************************************************%%%%%%%%"
#                  eval go build -v -x $BUILD_ARG 
                   eval go install -v -x $BUILD_ARG
                   ret_cmd=$?
                   error_msg="ERROR : Failed to run the build command!"
                   if [ $ret_cmd != 0 ]; then
                        echo "$error_msg"
                        exit;
                   fi
                   mv $GOPATH/bin/${arr_tmp[0]}"_main" $GOPATH/bin/${arr_tmp[1]}
                   echo "CLEANED and INSTALLED : ${arr_tmp[0]}"
                   break
               fi
           elif [ $1 == "clean" ]; then
           if [ $2 == "all" ]; then
               echo "**********************    CLEAN ONLY      ***************************"
               cd $main_path
               go clean -i -x
               echo "****************************************************************"
               echo "CLEANED : $subsys"
           elif [ $2 == ${arr_tmp[0]} ]; then
               echo "**********************    CLEAN      ***************************"
               cd $main_path
               go clean -i -x
               echo "%%%%%%%*************************************************%%%%%%%%"
               echo "CLEANED and INSTALLED : $subsys"
               break
           fi
       else
           echo "wrong first argument. Use build|cleanbuild"
           break
       fi
       done
   else
       echo "Wrong number of arguments. Use build|cleanbuild with subsystem to build"
   fi

答案1

Windows 上的 Bash 脚本

只有在安装了完整的 unix 样式子系统的情况下,才能在 Windows 中运行此脚本。该脚本需要安装标准 Unix 样式实用程序(例如date和)tr,并使用非限定命令执行date

粗心的剪切和粘贴

线路

                78,1-8        40%

看起来您粗心地从编辑器(vim?)中剪切并粘贴了此脚本,而不是复制或传输文件。应删除此行。

语法不正确

线路

export PATH=$PATH:C:/Users/user/Desktop/nxtxn-b2c/srcC:/Users/user/Documents/nxtxn-b2c/src:C:/Go/bin

包含多个错误

  • 您不能在 $PATH 元素中使用冒号,除非将其转义,因为冒号是分隔符。
  • ...b2c/src和之间应该有一个冒号C:/Users

相关内容