
¿Alguien puede ayudarme convirtiendo este script de Shell a bash script pl?
mi script de shell es el siguiente
#!/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
Respuesta1
Scripts Bash en Windows
Sólo puedes ejecutar esto en Windows si tienes instalado un subsistema completo de estilo Unix. El script espera que se instalen utilidades estándar de estilo Unix, como date
y, y que sean las que se ejecuten utilizando el comando no calificado.tr
date
Cortar y pegar descuidadamente
La línea
78,1-8 40%
Parece que cortaste y pegaste descuidadamente este script desde un editor (¿vim?) en lugar de copiar o transferir el archivo. Esta línea debería eliminarse.
Sintaxis incorrecta
La línea
export PATH=$PATH:C:/Users/user/Desktop/nxtxn-b2c/srcC:/Users/user/Documents/nxtxn-b2c/src:C:/Go/bin
contiene varios errores
- No puede usar dos puntos en elementos de $PATH, sin escapar de ellos, porque los dos puntos son un separador.
- Debe haber dos puntos entre
...b2c/src
yC:/Users