将&
附加到命令的结尾会在后台启动它。例如:安静地在后台启动进程
$ wget google.com &
[1] 7072
但是,这会打印一个作业号和PID。是否有可能防止这些?
注:我仍然想保留wget
的输出,这只是我想摆脱的[1] 7072
。
将&
附加到命令的结尾会在后台启动它。例如:安静地在后台启动进程
$ wget google.com &
[1] 7072
但是,这会打印一个作业号和PID。是否有可能防止这些?
注:我仍然想保留wget
的输出,这只是我想摆脱的[1] 7072
。
有一个选项到set
内置,set -b
,控制该线的输出,但选择限制为“立即”(设置时间)和“等待下一个提示”(当未设置)。即时打印的
例如,当选项设置:
$ set -b
$ sleep 1 &
[1] 9696
$ [1]+ Done sleep 1
和平常的行为,等待下一个提示:
$ set +b
$ sleep 1 &
[1] 840
$ # Press enter here
[1]+ Done sleep 1
所以就我所看到的,这些都可以”不被压制。可喜的是,虽然,作业控制消息不显示在非交互的shell:
$ cat sleeptest
#!/bin/bash
sleep 1 &
$ ./sleeptest
$
所以,如果你在后台在子shell启动命令,不会有任何消息。要做到这一点在交互式会话,你可以在这样的子shell(感谢David C. Rankin)运行命令:
$ (sleep 1 &)
$
,这也导致在没有作业控制提示。
嗯。非交互式shell可能工作... –
从Advanced Bash-Scripting Guide:
抑制
stdout
。cat $filename >/dev/null # Contents of the file will not list to stdout.
抑制
stderr
(来自Example 16-3)。rm $badname 2>/dev/null # So error messages [stderr] deep-sixed. Suppressing output from both stdout and stderr. cat $filename 2>/dev/null >/dev/null #1 If "$filename" does not exist, there will be no error message output. # If "$filename" does exist, the contents of the file will not list to stdout. # Therefore, no output at all will result from the above line of code. # # This can be useful in situations where the return code from a command #+ needs to be tested, but no output is desired. # # cat $filename &>/dev/null # also works, as Baris Cicek points out.
我仍然希望stdout/stderr正常;这只是我不想要的工作号码和PID。 –
** $> wget input&> NIL:**将输出发送到bin(删除)。 –
@ArifBurhan这将创建一个名为'NIL'的文件,不会将输出压缩到标准错误,而且该命令不会生成作业编号/ PID消息,因此这不起作用。 –
他的意思是'wget google.com&>/dev/null' –