How to delete and replace last line in the terminal using bash?

后端 未结 7 1199

I want to implement a progress bar showing elapsed seconds in bash. For this, I need to erase the last line shown on the screen (command \"clear\" erases all the screen, but

7条回答
  •  再見小時候
    2020-11-30 18:16

    In case the progress output is multi line, or the script would have already printed the new line character, you can jump lines up with something like:

    printf "\033[5A"

    which will make the cursor to jump 5 lines up. Then you can overwrite whatever you need.

    If that wouldn't work you could try printf "\e[5A" or echo -e "\033[5A", which should have the same effect.

    Basically, with escape sequences you can control almost everything in the screen.

提交回复
热议问题