gpt4 book ai didi

linux - ./而不是/在 crontab 中

转载 作者:太空宇宙 更新时间:2023-11-04 03:52:36 24 4
gpt4 key购买 nike

我在 crontab(或普通 shell)中尝试执行 sh 时遇到错误。我创建了一个用户 Xuser,并在他的主目录中创建了一个指向/opt/app 的符号链接(symbolic link)/opt/app 与此 --> drwxrwxr-- Xuser 测试在这个文件夹中,我保存了一些 sh ​​和 jar。

现在在该用户的 crontab 中,或者如果我尝试执行此命令,甚至在 shell 中:

./opt/app/bin/ind.sh
-bash: ./opt/app/bin/ind.sh: No such file or directory

Sh 文件是

#!/bin/sh
export JAVA_HOME=/usr/java/latest/
export PATH=$PATH:$JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin

java -jar /opt/app/bin/ind.jar

如果我在 ./它有效

. /opt/app/bin/ind.sh
: command not found
Error: Unable to access jarfile /opt/app/bin/ind.jar

(访问SH但似乎问题传递到jar了哈哈哈)

有人注意到这个问题了吗?

谢谢!!!

最佳答案

有一个很大的区别,当您在 ./ 之间放置空格时,. 不再是文件路径的一部分,而是 source 的别名,表示“在当前 shell 中执行此文件的内容”。

// execute in a subshell
./foo/bar/baz.sh

// execute in this shell
. ./foo/bar/baz.sh

// this is not the same file as previously, unless we are at the root (/)
. /foo/bar/baz.sh

关于linux - ./而不是/在 crontab 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25768327/

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