What is </dev/null in bash?

后端 未结 4 938
死守一世寂寞
死守一世寂寞 2020-11-30 22:58

In bash, standard (1) and error (2) output can be re-routed and discarded with:

>/dev/null 2>&1

But the following example does s

4条回答
  •  时光取名叫无心
    2020-11-30 23:40

    is used to avoid the script wait for input.

    Quoting from the usage of < /dev/null & in the command line:

    < /dev/null is used to instantly send EOF to the program, so that it doesn't wait for input (/dev/null, the null device, is a special file that discards all data written to it, but reports that the write operation succeeded, and provides no data to any process that reads from it, yielding EOF immediately). & is a special type of command separator used to background the preceding process.

    So the command:

    nohup myscript.sh >myscript.log 2>&1 

    will move to background the command, outputing both stdout and stderr to myscript.log without waiting for any input.

提交回复
热议问题