我正在开发一个文件处理项目,并尝试在 PuTTY 中运行一个名为 runProcessing.sh 的 shell 脚本。服务器使用ksh。我的主管告诉我使用 ./ runProcessing.sh <param1> <param2>
执行脚本时,但每当我使用 ./时,它都会显示 cannot execute
或file not found
。每当我输入 runProcessing.sh
,它返回空指针异常,我现在一直在处理该异常以继续我的任务。
我理解 ./在运行脚本时的作用,但我不确定为什么当我尝试用它运行脚本时它不起作用。有什么建议或建议吗?我是 Linux/UNIX 新手。
这是我的脚本:
#!/bin/ksh
#
# Script to download processing files from the appropriate target
#
# $Id: runProcessing.sh 604 2013-01-14 21:56:35Z alex_rempel $
#
DIR=`dirname $0`
. $DIR/setEnvironment.sh
java $LDAPRUNMODE $JAVAOPT com.webproject.db.processing.FPJob --logdir $CISLOGDIR --file [2] $*
RET=$?
if [ $RET -gt 0 ]
then
echo
echo
echo "------ runProcessing.sh Failed ------"
echo
echo
exit $RET
最佳答案
空指针异常来自您的 Java 程序,因此它们意味着该进程实际上已启动。通常,它们并不表明您的 shell 脚本或其调用存在问题。
. something # this reads the file `something`, running each line as a command
# in your current shell. (Actual behavior is a bit more sophisticated
# than that, but it's close enough).
./something # this tries to run the file `something` in the current directory as
# an executable. It doesn't need to be a shell script -- it can be
# any kind of executable, and if it has a shebang line, that will be
# honored to determine the interpreter or shell to use.
./ something # <- this is simply invalid.
也就是说,您可以通过像这样启动脚本来准确记录脚本正在运行的命令:
ksh -x ./something
这将显示您的脚本运行的命令。如果故障是由脚本错误启动 JVM 引起的,您可以据此判断预期调用与实际调用有何不同。
关于bash - 使用 ./dot-slash 运行 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17433375/