tekina
tekina

Reputation: 572

Run ant command from shell script

I'm writing a script to automate compilation of java projects, and using ant for the same. When I run the ant command directly in bash shell it builds the project properly. However, if I run the exact same command from a shell script, I'm getting the following error:

./build.sh: line 21: Apache: command not found

Line 21 in my build.sh file is:

`ant clean build -v -buildfile $BUILDFILE`

where $BUILDFILE=auto_build.xml.

I've also added the path to ant bin folder in .bashrc $ANT_HOME has the value /usr/share/ant

ant -version gives me Apache Ant(TM) version 1.9.3 compiled on April 8 2014 (This command also does not work if added to a shell script)

Upvotes: 1

Views: 4984

Answers (1)

M A
M A

Reputation: 72844

I suspect the problem is due to the backticks around the command. Try replacing

`ant clean build -v -buildfile $BUILDFILE`

with

ant clean build -v -buildfile $BUILDFILE

The backticks indicate that the bash interpreter should execute the output of the ant command as a command by itself.

See https://unix.stackexchange.com/questions/27428/what-does-backquote-backtick-mean-in-bash.

Upvotes: 2

Related Questions