问题描述
我想将一些输出传递到另一个程序并显示进度条.
I want to pipe some output to another program and display a progress bar.
代码看起来像这样:
echo "Progress:"
(for i in {1..10}; do echo $i; echo "." > screen; sleep 1; done) | xargs echo
其中 screen
会将其定向到屏幕.这是行不通的,因为它只会将点写入文件屏幕.
where screen
would direct it to the screen. This is not working because it will just write the dots to the file screen.
我想做的是输出."在脚本运行时,同时一次将所有 echo"$ i"
进行管道传输,因此只有一个管道传输发生.
What I want to do is outputting the "." while the script is running and piping all the echo "$i"
at once at the end, so only one piping occurs.
推荐答案
您必须将回显发送到tty设备.例如,echo'somthing'>/dev/tty
You have to send the echo to the tty device. For example, echo 'somthing' > /dev/tty
但是,如果您只想在屏幕上显示点,则不需要任何重定向.只回显'.'
But if you only want to show dots in the screen you don't need any redirection. Only echo '.'
这篇关于重定向到屏幕和管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!