-6

can anyone help me by converting this shell script to bash script pl.

my shell scrpit is as follows

#!/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

closed as too broad by kenorb, Debra, Rajesh S, music2myear, Tim_Stewart Feb 28 at 19:29

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    #!/bin/bash - it is already a script run by bash. Why does it need any conversion? – DavidPostill Apr 15 '16 at 10:50
  • 2
    Note: Your export PATH... statement is broken. – DavidPostill Apr 15 '16 at 10:50
  • 1
    @DavidPostill hah, very broken indeed, in so many ways too. Wonder what he's doing with bash on windows if he doesn't even know how to use it in the first place... – Cestarian Apr 15 '16 at 10:57
  • then how to run it in windows system. when i run it bash script.sh , m getting error – mpower Apr 15 '16 at 11:05
  • ` m getting error`... Mentioning which error might help.... – Hennes Apr 15 '16 at 11:10
2

Bash scripts on Windows

You can only run this in Windows if you have a full unix-style subsystem installed. The script expects standard Unix style utilities such as date and tr to be installed and to be what gets executed using the unqualified date command.

Careless cut & paste

The line

                78,1-8        40%

Looks like you carelessly cut & pasted this script from an editor (vim?) rather than copying or transferring the file. This line should be deleted.

Incorrect syntax

The line

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

contains several errors

  • You can't use colons in elements of $PATH, without escaping them, because the colon is a separator.
  • There should be a colon between ...b2c/src and C:/Users

Not the answer you're looking for? Browse other questions tagged or ask your own question.