从 bash 脚本中清除当前行上的所有文本

Jon*_*nny 1 macos bash terminal

我怎样才能ctrl u从 bash 脚本引起?

即我想删除一行光标左侧的所有字符,并将光标放在第 0 列。

解决方法可能是打印\r,然后是清除光标右侧的内容。

我不想清除整个终端屏幕。

更新:

我使用的解决方案(在 PHP 中):

echo 'mydata' . "\033[0K\r";
Run Code Online (Sandbox Code Playgroud)

Ale*_*-A. 5

基本上你可以做这样的事情:

while :; do # an infinite loop just for demonstration
    echo "$RANDOM" # print your stuff here
    sleep 0.2
    tput cuu1 # move cursor up by one line
    tput el # clear the line
done
Run Code Online (Sandbox Code Playgroud)

使用man tput以获取更多信息。要查看功能列表,请使用man terminfo