Pau*_*ce. 11
试试这个:
$ printf "12345678\rABC\n"
ABC45678
Run Code Online (Sandbox Code Playgroud)
如您所见,输出回车会将光标移动到同一行的开头.
你可以像这样清除这条线:
$ printf "12345678\r$(tput el)ABC\n"
ABC
Run Code Online (Sandbox Code Playgroud)
使用tput
为您提供了一种将控制字符发送到终端的便携方式.有关man 5 terminfo
控制代码的列表,请参阅.通常,您需要将序列保存在变量中,这样您就不需要重复调用外部实用程序:
$ clear_eol=$(tput el)
$ printf "12345678\r${clear_eol}ABC\n"
ABC
Run Code Online (Sandbox Code Playgroud)