1

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)

2
  • What is the running environment of your script? can you print which ant in your script to verify that you running the right ant command. Commented Feb 1, 2015 at 14:10
  • which ant=/usr/share/ant Commented Feb 1, 2015 at 14:13

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This was the case indeed. This is my first time writing shell scripts and I got confused about when to use backticks. Still got quite a bit to learn, I guess. Will accept the answer as soon as SO allows me to. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.