如何展示在同一行更新回声 [英] How to show and update echo on same line

查看:110
本文介绍了如何展示在同一行更新回声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在击(在Linux中)以下

I have the following in Bash (In Linux)

for dir in Movies/*
do
  (cd "$dir" && pwd|cut -d \/ -f5|tr -s '\n' ', ' >> ../../movielist &&
  exiftool * -t -s3 -ImageSize -FileType|tr -s '\t' ',' >> ../../movielist )
echo "Movie $movies - $dir ADDED!"
let movies=movies+1
done

但我想使它所以回声显示下一行下面的回声(与上次回声输出并置,但取代它),这样使它看起来就像是更新。类似于如何与百分之进度条将显示在同一行上。

But I wish to make it so the "echo" shows the following echo on the next line (Not concatenate with the last echo output but replace it) so to make it look like it is updating. Similar to how a progress bar with percent would show on the same line.

推荐答案

好吧,我没有正确此阅读人回声

Well I did not read correctly the man echo page for this.

回声有2种选择,可以做到这一点,如果我加了第三个转义字符。

echo had 2 options that could do this if I added a 3rd escape character.

2个选项是 -n -e

-n 将不输出其后的换行符。因此,从每个我赞同一些时间去一个新的生产线节省了我。

-n will not output the trailing newline. So that saves me from going to a new line each time I echo something.

-e 将让我跨preT反斜线符号。

-e will allow me to interpret backslash escape symbols.

猜猜我想用这个东西逃跑符号: \\ r 。是的,回车会送我回到起点,它会在视觉上看起来像我在同一线路上更新。

Guess what escape symbol I want to use for this: \r. Yes, carriage return would send me back to the start and it will visually look like I am updating on the same line.

所以回声线是这样的:

回声-ne电影$电影! - $ DIR补充说:\\\\ - [R

我只好逃逃逸符号所以猛砸不会杀死它。这就是为什么你在那里看到2 \\ 符号。

I had to escape the escape symbol so Bash would not kill it. that is why you see 2 \ symbols in there.

正如威廉所说,的printf 也可以做类似的(甚至更广泛的)的任务是这样的。

As mentioned by William, printf can also do similar (and even more extensive) tasks like this.

这篇关于如何展示在同一行更新回声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆