# make function run async in the background of some sort
# not fully detached from the parent executing script
# see: https://gist.github.com/bluekezza/e511f3f4429939a0f9ecb6447099b3dc#file-nohup_function-sh
function_to_run() {
  while true; do
    echo "function1"
    sleep 1
  done
}
main() {
  (
    # start a group. statements will be executed in a sub-shell
    # see: https://www.gnu.org/software/bash/manual/html_node/Command-Grouping.html#Command-Grouping

    # catch the SIGHUP and SIGINT signals and ignore them
    # see: trap in https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html#Bourne-Shell-Builtins
    trap '' HUP INT

    # call the function to be executed
    function_to_run
  ) </dev/null 2>&1 1>nohup.out &
  # mark the end of the group. we can now control the groups file handles and execution
  # </dev/null: disconnect our forked process from stdin by pointing stdin to /dev/null
  # 2>&1: anything written to stderr should instead be written to stdout
  # 1>nohup.out: redirect stdout (which also includes stderr from above) to the file
  # &: execute the command asychronously
  # see: https://www.gnu.org/software/bash/manual/html_node/Lists.html#Lists
}
# main

# NOTE: `</dev/null 2>&1 1>nohup.out` points stderr to /dev/tty
# and then points stdout to nohup.out.
# the result is that error output is now going to stdout.
#
# you want `</dev/null 1>nohup.out 2>&1`
# which redirects both stderr and stdout to nohup.out.
