0

For instance, how would I kill tail when wget finishes.

#!/bin/bash
wget http://en.wikipedia.org/wiki/File:Example.jpg &
tail -f example.log
4

1 回答 1

5

也许这会更好——虽然我还没有测试过:

#!/bin/bash
LOGFILE=example.log
> $LOGFILE # truncate log file so tail begins reading at the beginning
tail -f $LOGFILE &
# launch tail and background it
PID=$!
# record the pid of the last command - in this case tail
wget --output-file=$LOGFILE http://en.wikipedia.org/wiki/File:Example.jpg
kill $PID
#launch wget and when finished kill program (tail) with PID

这取决于 tail 尽管在后台仍然会在控制台上显示它的输出这一事实。不过,这不会那么容易重定向。

于 2013-11-12T08:20:42.167 回答