gpt4 book ai didi

bash - 使用 ./点斜线运行 shell 脚本

转载 作者:行者123 更新时间:2023-12-04 04:51:11 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Why do you need ./ (dot-slash) before executable or script name to run it in bash?

(9 个回答)


9 个月前关闭。




我正在处理一个文件处理项目,我正在尝试在 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 - 使用 ./点斜线运行 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17433375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com