Call a function using nohup Call a function using nohup shell shell

Call a function using nohup


Another solution:

function background {    echo TEST}export -f background nohup bash -c background &


nohup applies to commands and not to script functions.

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

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

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

nohup ./func.sh &

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


I find a working solution for me - define the function in a file (e.g. .functions) then run the function with nohup:

nohup bash -c "source .functions; function1" &

Tested on Ubuntu 13.04.