通过 nohup 在 运行 的脚本中调用脚本

Calling a script within a script that was run via nohup

我有一个脚本,当我 运行 屏幕时,它可以完美运行。 目录结构如下:

/home/username/processing/ScriptRunning
/home/username/processing/functions/include_me

在脚本中,它会打开另一个脚本,只需执行以下操作即可包含一个函数:

#!/bin/bash
#This is ScriptRunning script
. functions/include_me

现在,当我使用以下 nohup 命令调用脚本时:

nohup/home/username/processing/ScriptRunning

这是输出:

/home/username/processing/ScriptRunning: line 3: /home/username/functions/include_me: No such file or directory

似乎遗漏了 processing 目录

我已将 ScriptRunning 中的行更改为具有完整路径,既硬编码为 /home/username/processing 并将其作为通过调用 $(pwd) 创建的变量,但是错误是一样的。

我真的错过了这么愚蠢的东西吗?

这不是 nohup 问题。您正在包含一个使用相对文件名的源文件。尝试:

. $(dirname ${BASH_SOURCE})/functions/include_me

包含相对于 ${BASH_SOURCE}

的源文件