bash - 使用 ./dot-slash 运行 shell 脚本

标签 bash shell unix scripting putty

我正在开发一个文件处理项目,并尝试在 PuTTY 中运行一个名为 runProcessing.sh 的 shell 脚本。服务器使用ksh。我的主管告诉我使用 ./ runProcessing.sh <param1> <param2>执行脚本时,但每当我使用 ./时,它都会显示 cannot executefile 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/

相关文章:

linux - 获取 setup.sh 会给出 bash 错误/tmp/setup.sh.DPE4BtgiZY : cannot overwrite existing file

shell - 在 shell 中, “2>&1 &” 是什么?

c - shell 作业控制

linux - grep 多个文件上的多个字符串

linux - 如何解析脚本中差异的结果?

bash - 使用 sed 更改文件中一行的位置

bash - 在bash中读取和解析文件及其参数

linux - 计算列中的出现次数并获取整行

linux - 如果不同文件中相同位置的字段值为 "zero",则修改一个文件的字段值

php - 如何终止与 grep 匹配时间超过 30 分钟的进程?