问题
How can I cause ctrl u from a bash script?
Ie I want to remove all characters left of cursor on a line, and put cursor in column 0.
A workaround could be printing \r, followed by something to clear right of cursor.
I don't want to clear the whole terminal screen.
Update:
The solution I use (in PHP):
echo 'mydata' . "\033[0K\r";
回答1:
Basically you can do something like this:
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
Use man tput for more info. To see the list of capabilities use man terminfo
来源:https://stackoverflow.com/questions/24319932/clear-all-text-on-current-line-from-a-bash-script