Reputation: 2881
I am having some trouble running ant. Here is a simplified verison of my problem. I have a shell script script1.sh:
export ANT_HOME=/opt/Ant
ant -version
This works. but when I try create another script script2:
cd /location/of/script1
sudo -E ./script1.sh | tee log.txt
I get the error ant: command not found.
Does anyone know why this is happening.
Upvotes: 1
Views: 24472
Reputation: 3167
Without knowing what shell, or seeing more of the scripts it's hard to tell exactly what is happening. But if you want script2 to know about ANT_HOME you're probably going to need to source
or eval
script1. See here. Also I know pipes '|' cause Bash to perform operations within sub-shells which can be problematic under certain circumstances (if you're using Bash).
EDIT: Double check that you are using the version of ant that you think you are:
#!/bin/bash
# Capital A here seems suspicious to me...
export ANT_HOME=/opt/Ant
echo "`${ANT_HOME}/ant -version`"
Upvotes: 0
Reputation: 4703
Sounds like you're losing your PATH
setting after sudo
. Try adding echo $PATH
in script1.sh
to see the before and after values. Or just define script1.sh
as
export ANT_HOME=/opt/Ant
${ANT_HOME}/ant -version
Upvotes: 4