How to include nohup inside a bash script? How to include nohup inside a bash script? unix unix

How to include nohup inside a bash script?


Try putting this at the beginning of your script:

#!/bin/bashcase "$1" in    -d|--daemon)        $0 < /dev/null &> /dev/null & disown        exit 0        ;;    *)        ;;esac# do stuff here

If you now start your script with --daemon as an argument, it will restart itself detached from your current shell.

You can still run your script "in the foreground" by starting it without this option.


Create an alias of the same name in your bash (or preferred shell) startup file:

alias mandacalc="nohup mandacalc &"


Why don't you just make a script containing nohup ./original_script ?