http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion/posts/bash/have-bash-script-fork-itself-into-background.html
Although you could trigger it manually when calling your script, sometimes you want it to be conditional - if a lock exists you may not want to fork The mechanism this snippet uses is fairly simple, it checks to see if an environment variable is set, if not, it sets the variable and forks itself into the background, using nohup to ignore any session disconnects Details Language: BASH License: BSD-3-Clause Snippet # See if the env flag is set if [ " $FORKED_TO_BG " = "" ] then # Fork self to background...