错误执行 ant :-bash: ant: command not found
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30149381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error executing ant :-bash: ant: command not found
提问by NewUser
I am trying to deploy my application in a Linux box, I have a file called setAppPath.sh file as:
我正在尝试在 Linux 机器中部署我的应用程序,我有一个名为 setAppPath.sh 的文件,如下所示:
#!/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:
当我尝试执行ant
命令时,我收到一条错误消息:
-bash: ant: command not found
The echo $ANT_HOME
is printing my ant home location the PATH is printed properly too.
echo$ANT_HOME
正在打印我的 ant home 位置,PATH 也打印正确。
After execting setAppPath.sh
file I tried echo $ANT_HOME it gave empty line.
执行setAppPath.sh
文件后,我尝试 echo $ANT_HOME 它给出了空行。
Please help me figuring out this issue.
请帮我弄清楚这个问题。
Edit 1:which ant
give no ant
编辑1:不which ant
给蚂蚁
I am using sh setAppPath.sh command to execute the sh file.
我正在使用 sh setAppPath.sh 命令来执行 sh 文件。
采纳答案by Mat
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.
当您正常运行脚本时,发生的情况是您的 shell 启动了一个新进程,脚本在该进程中运行,当脚本完成时,该进程终止并且控制权返回到您的 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.
脚本对其环境所做的所有修改都会随之消失。这些更改对父 shell 没有影响。如果您尝试cd
在脚本中运行并期望父 shell 移动,则相同。
To run your script in the context of your shell and not in a subprocess, use the source
or .
commands:
要在 shell 的上下文中而不是在子进程中运行脚本,请使用source
或.
命令:
source setAppPath.sh
. setAppPath.sh