Running bash commands in the background properly

  • I found 'screen' to be pretty handy for running scripts in the background. Then you can also reattach later to look at stdout as it's running.

  • Understanding whether background jobs get killed (via SIGHUP) or orphaned is not obvious without reading about the huponexit shopt. I've found some recent distros to not enable huponexit by default for login shells, and so this isn't always an issue.

    More importantly, understanding how your jobs behave when your SSH session is killed can be a huge timesaver.

  • The random shell output from "background" apps never bothered me that much ;-) Crunchbang you can just press F2 and get auto-complete and launch commands with no shell output. Ubuntu has something similar. If you have terminator, just split the pane if you need a fresh one, or drag the terminal to another workspace and it's out of the way. Also tmux has ^bd to "detach" I think.

  • Wouldn't it be better to simply do

        "$@" "${FD[@]" &
    
    And also remember to

        alias ds='ds '
    
    to enable alias expansion.

  • Added to /bin/sh