Running bash commands in the background without printing job and process ids

前端 未结 8 1350
余生分开走
余生分开走 2020-12-07 22:09

To run a process in the background in bash is fairly easy.

$ echo \"Hello I\'m a background task\" &
[1] 2076
Hello I\'m a background task
[1]+  Done             


        
8条回答
  •  生来不讨喜
    2020-12-07 22:17

    Based on this answer, I came up with the more concise and correct:

    silent_background() {
        { 2>&3 "$@"& } 3>&2 2>/dev/null
        disown &>/dev/null  # Prevent whine if job has already completed
    }
    silent_background date
    

提交回复
热议问题