Linux的shell脚本:调用由nohup的功能 [英] Linux shell script: call a function by nohup

查看:3289
本文介绍了Linux的shell脚本:调用由nohup的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打电话给使用nohup这个像这样的一个功能:

I am trying to call a function using nohup such as this:

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

}

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

但也许功能不是由nohup的看到,我看到terinal此消息:

but maybe the function isn't seen by nohup and I see this message in the terinal:

nohup的:无法运行命令'功能1:没有这样的文件或字典

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

我不希望我的函数来创建新的SH文件。我该如何解决这个问题?谢谢你。

I don't want to create new sh file for my function. How can I fix this? thank you.

推荐答案

的nohup 适用于命令而不是脚本功能。

nohup applies to commands and not to script functions.

例如,脚本(比如func.sh),包含功能1()应调用的函数 - :

For example, the script (say func.sh) that contains function1() should call the function-:

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

}

function1

现在调用在后台与的nohup 脚本func.sh - :

Now call the script func.sh with nohup in the background-:

nohup ./func.sh &

如果您需要从脚本中禁用挂起信号使用shell内置的陷阱。的例子忽略SIGHUP但可用于忽略他人(例如信号情报)。

If you need to disable the hangup signal from within the script use the shell built-in trap. The example ignores SIGHUP but can be used to ignore others (e.g. SIGINT).

trap "" HUP   # script will ignore HANGUP signal

这篇关于Linux的shell脚本:调用由nohup的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆