小编مري*_*ربي的帖子

有没有办法在不清除屏幕的情况下替换行?

printf "line one\n"
printf "line two\n"
Run Code Online (Sandbox Code Playgroud)

在这些打印输出之后,我想替换第一并打印其他内容(不使用clear)。我试过这样的命令:

printf "line one\n"
printf "line two\r"
Run Code Online (Sandbox Code Playgroud)

这不是我想要的,因为它替换了最后一行line two,而不是line one.

我想做的事:

printf "line one\n"
printf "line two\n"
sleep 0.5
somecode "line three"
Run Code Online (Sandbox Code Playgroud)

我想要的输出:

line three
line two
Run Code Online (Sandbox Code Playgroud)

linux bash shell printf echo

2
推荐指数
1
解决办法
76
查看次数

标签 统计

bash ×1

echo ×1

linux ×1

printf ×1

shell ×1