Search code examples
linuxbashscriptingtty

Temporary clear tty


A number of commands (eg watch, less) are able to temporarily clear the tty to display a full screen of information, then when the command exits restore the original tty content.

Is there a way to achieve this in a bash script?


Solution

  • Use tput. Here's a minimal example:

    #!/bin/bash  
    tput smcup    # save the screen
    clear         # clear the screen
    
    echo this is some text on a blank screen
    echo press any button to exit..
    read -n1
    
    tput rmcup    # reset the screen