linux - 使用 nohup 调用函数

标签 linux bash function shell nohup

我正在尝试使用 nohup 调用函数,如下所示:

function1(){
    while true 
    do
        echo "function1"
        sleep 1
    done
}

nohup function1 & 
# ...... some other code

但可能是 nohup 看不到该函数,我得到了这个错误:

nohup: failed to run command `function1' : No such file or dictionary

我不想为我的函数创建新的 sh 文件。我该如何解决这个问题?

最佳答案

另一种解决方案:

function background {
    echo TEST
}
export -f background 

nohup bash -c background &

关于linux - 使用 nohup 调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16435629/

相关文章:

javascript - 变量在函数中灰显

c++ - 具有两个函数头的菜单驱动程序中的 undefined reference

regex - + 正则表达式在 sed 中不起作用

c - 在我自制的 shell 中添加键盘快捷键

bash - 实时 stdout 的输出重定向在将其通过管道传输到 uniq 或 awk 后不起作用

mongodb - 用于编辑 MongoDB 配置文件的 Bash 脚本

c++ - 我的 C++ 函数在不应该的时候破坏了变量

linux - Shell 脚本 ls 指向第 n 个文件

linux - 想要操纵日期命令来计入今天之后的 future

linux - Bash:重定向停止