Questions tagged «process-substitution»

6
将stdout捕获到变量,但仍将其显示在控制台中
我有一个bash脚本,它调用了几个长时间运行的进程。由于处理原因,我想将这些调用的输出捕获到变量中。但是,由于这些进程是长期运行的进程,因此我希望rsync调用的输出实时显示在控制台中,而不是事后显示。 为此,我找到了一种方法,但是它依赖于将文本输出到/ dev / stderr。我觉得输出到/ dev / stderr并不是一个好方法。 VAR1=$(for i in {1..5}; do sleep 1; echo $i; done | tee /dev/stderr) VAR2=$(rsync -r -t --out-format='%n%L' --delete -s /path/source1/ /path/target1 | tee /dev/stderr) VAR3=$(rsync -r -t --out-format='%n%L' --delete -s /path/source2/ /path/target2 | tee /dev/stderr) 在上面的示例中,我多次调用rsync,并且希望在处理文件时看到它们的名称,但是最后我仍然希望将输出包含在变量中,因为稍后将对其进行解析。 有没有一种“清洁”的方法来实现这一目标? 如果有所作为,我正在使用Ubuntu 12.04,bash 4.2.24。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.