Reputation: 1609
I am trying to write a script that displays its output to the terminal only while it's running, much like the 'less' or 'ssh' commands.
When I launch said script, it would take over the whole terminal, print what it needs to print, and then when I exit the script, I would return to my terminal where the only record that my script has run will be the line that shows the command itself. When I scroll up, I don't want to see what my script output.
[snoopdougg@machine /home/snoopdougg/logs]$ ls
alog.log blog.log clog.log myScript.sh
[snoopdougg@machine /home/snoopdougg/logs]$ whoami
snoopdougg
[snoopdougg@machine /home/snoopdougg/logs]$ ./myScript.sh
[snoopdougg@machine /home/snoopdougg/logs]$
(Like nothing ever happened... but myScript.sh would have print things to the terminal while it was running).
How can I do this?
Upvotes: 2
Views: 166
Reputation: 530950
You're talking about the alternate screen, which you can access with a pair of terminal attributes, smcup
and rmcup
. Put this in a script and run it for a small demo:
tput smcup
echo hello
sleep 5
tput rmcup
Upvotes: 4