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.
Just put trap '' HUP
on the beggining of your script.
Also if it creates child process someCommand&
you will have to change them to nohup someCommand&
to work properly... I have been researching this for a long time and only the combination of these two (the trap and nohup) works on my specific script where xterm closes too fast.