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

前端 未结 8 1323
余生分开走
余生分开走 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:35

    In some newer versions of bash and in ksh93 you can surround it with a sub-shell or process group (i.e. { ... }).

    /home/shellter $ { echo "Hello I'm a background task" & } 2>/dev/null
    Hello I'm a background task
    /home/shellter $
    
    0 讨论(0)
  • 2020-12-07 22:35

    Try:

    user@host:~$ read < <( echo "Hello I'm a background task" & echo $! )
    user@host:~$ echo $REPLY
    28677
    

    And you have hidden both the output and the PID. Note that you can still retrieve the PID from $REPLY

    0 讨论(0)
提交回复
热议问题