Reputation: 3819
I am trying to deploy my application in a Linux box, I have a file called setAppPath.sh file as:
#!/bin/sh
APP_HOME=`pwd`
ANT_HOME=$APP_HOME/lib/ant
echo $ANT_HOME
PATH=$ANT_HOME/bin:$APP_HOME/scripts/unix:$PATH
echo $PATH
chmod +x $ANT_HOME/bin/ant
chmod +x $APP_HOME/scripts/unix/*.sh
export APP_HOME ANT_HOME PATH
When I try to execute ant
command I get an error message as:
-bash: ant: command not found
The echo $ANT_HOME
is printing my ant home location the PATH is printed properly too.
After execting setAppPath.sh
file I tried echo $ANT_HOME it gave empty line.
Please help me figuring out this issue.
Edit 1: which ant
give no ant
I am using sh setAppPath.sh command to execute the sh file.
Upvotes: 2
Views: 6902
Reputation: 206659
When you run your script normally, what happens is that your shell starts a new process, the script runs in that process, and when the script is done the process dies and control returns to your shell.
All modifications that the script did to its environment die with it. The changes have no effect on the parent shell. Same if you're trying to run cd
in a script and expecting the parent shell to move.
To run your script in the context of your shell and not in a subprocess, use the source
or .
commands:
source setAppPath.sh
. setAppPath.sh
Upvotes: 1