语法错误接近意外令牌“do”

时间:2021-09-04 22:44:06

I am trying to convert a .bat file into .sh file here is my lines of code

我想把。bat文件转换成。sh文件这是我的代码行

#!/bin/sh
./setenv.sh
export _LIBJARS=for i in [$XYZ_HOME$/lib/*.jar];do source $XYZ_HOME$/bin/append.bat i
export CLASSPATH=$ANT_HOME$/lib/ant.jar;$_LIBJARS$$ANT_HOME$/bin/ant -buildfile $XYZ_HOME$/build.xml $1 $2 $3 $4

After writing these line I wrote chmod 755 ./build.sh then I wrote ./build.sh test-deploy

写完这一行后,我写了chmod 755。然后我写了。sh test-deploy

I am getting the following error:

我得到了以下错误:

./build.sh: line 3: syntax error near unexpected token `do'
./build.sh: line 3: `export _LIBJARS=for i in [$XYZ_HOME$/lib/*.jar];do source $XYZ_HOME$/bin/append.bat i'

My .Bat file is like

我的。bat文件就像

call setenv.bat

set _LIBJARS=
for %%i in (%XYZ_HOME%\lib\*.jar) do call %XYZ_HOME%\bin\append.bat %%i

set CLASSPATH=%ANT_HOME%\lib\ant.jar;%_LIBJARS%

%ANT_HOME%\bin\ant -buildfile %XYZ_HOME%\build.xml %1 %2 %3 %4

Or any tutorial to understand the lines of code or related to shell and bash file please suggest me.

或任何理解代码行或与shell和bash文件相关的教程,请建议我。

2 个解决方案

#1


2  

Bash Shell and Batch are two completely different programming languages with their own syntax and the way they work.

Bash Shell和Batch是两种完全不同的编程语言,它们具有各自的语法和工作方式。

For example:

例如:

call setenv.bat

Will run setenv.bat in your script and return control to your current script. However:

运行setenv。在脚本中输入bat并将控件返回到当前脚本。然而:

./setenv.sh

Will spawn a new shell, set the environment in that shell, and then return to the parent shell where those environment variables are not set. To do the equivalent in shell, you must source in setenv.sh:

将生成一个新的shell,在该shell中设置环境,然后返回到未设置这些环境变量的父shell。

. ./setenv.sh

OR

source ./setenv.sh

The first is compatible to all Bourne Style shells. The last is more readable, but may not be compatible with different shells.

第一种是兼容所有伯恩风格的shell。最后一个更容易读,但可能与不同的shell不兼容。

set _LIBJARS=
for %%i in (%XYZ_HOME%\lib\*.jar) do call %XYZ_HOME%\bin\append.bat %%i

set CLASSPATH=%ANT_HOME%\lib\ant.jar;%_LIBJARS%

In Shell, you can do this:

在壳牌,你可以这样做:

export CLASSPATH=%ANT_HOME%\lib\ant.jar
for jar in ($XYZ_HOME/lib/*.jar)
do
    CLASSPATH="$CLASSPATH:$jar"
done

Remember, this is only taking place INSIDE this shell script. Unlike Batch, it's not affect the parent shell, so using $CLASSPATH is fine.

记住,这只发生在shell脚本中。与Batch不同,它不影响父shell,因此使用$CLASSPATH是可以的。

Finally:

最后:

$ANT_HOME/bin/ant -buildfile $XYZ_HOME/build.xml $*

The $* will work no matter how many target are passed.

无论通过多少个目标,$*都将有效。

#2


0  

This might be how you want it to do:

这可能是你想要的:

#!/bin/sh

. ./setenv.sh  # Must 'source' or else you won't get the values.
_LIBJARS=

for I in "$XYZ_HOME/lib/"*.jar; do
    . "$XYZ_HOME/bin/append.sh" "$I"
done

export CLASSPATH=$ANT_HOME/lib/ant.jar:$_LIBJARS
"$ANT_HOME/bin/ant" -buildfile "$XYZ_HOME/build.xml" "$1" "$2" "$3" "$4"  ## Or perhaps it should simply be "$@"?

#1


2  

Bash Shell and Batch are two completely different programming languages with their own syntax and the way they work.

Bash Shell和Batch是两种完全不同的编程语言,它们具有各自的语法和工作方式。

For example:

例如:

call setenv.bat

Will run setenv.bat in your script and return control to your current script. However:

运行setenv。在脚本中输入bat并将控件返回到当前脚本。然而:

./setenv.sh

Will spawn a new shell, set the environment in that shell, and then return to the parent shell where those environment variables are not set. To do the equivalent in shell, you must source in setenv.sh:

将生成一个新的shell,在该shell中设置环境,然后返回到未设置这些环境变量的父shell。

. ./setenv.sh

OR

source ./setenv.sh

The first is compatible to all Bourne Style shells. The last is more readable, but may not be compatible with different shells.

第一种是兼容所有伯恩风格的shell。最后一个更容易读,但可能与不同的shell不兼容。

set _LIBJARS=
for %%i in (%XYZ_HOME%\lib\*.jar) do call %XYZ_HOME%\bin\append.bat %%i

set CLASSPATH=%ANT_HOME%\lib\ant.jar;%_LIBJARS%

In Shell, you can do this:

在壳牌,你可以这样做:

export CLASSPATH=%ANT_HOME%\lib\ant.jar
for jar in ($XYZ_HOME/lib/*.jar)
do
    CLASSPATH="$CLASSPATH:$jar"
done

Remember, this is only taking place INSIDE this shell script. Unlike Batch, it's not affect the parent shell, so using $CLASSPATH is fine.

记住,这只发生在shell脚本中。与Batch不同,它不影响父shell,因此使用$CLASSPATH是可以的。

Finally:

最后:

$ANT_HOME/bin/ant -buildfile $XYZ_HOME/build.xml $*

The $* will work no matter how many target are passed.

无论通过多少个目标,$*都将有效。

#2


0  

This might be how you want it to do:

这可能是你想要的:

#!/bin/sh

. ./setenv.sh  # Must 'source' or else you won't get the values.
_LIBJARS=

for I in "$XYZ_HOME/lib/"*.jar; do
    . "$XYZ_HOME/bin/append.sh" "$I"
done

export CLASSPATH=$ANT_HOME/lib/ant.jar:$_LIBJARS
"$ANT_HOME/bin/ant" -buildfile "$XYZ_HOME/build.xml" "$1" "$2" "$3" "$4"  ## Or perhaps it should simply be "$@"?