Here I want something like the way aircrack-ng
does to display text in the terminal screen, or like matrix scripts … !
For example, if my terminal screen already contains 4 lines, I want to update the 1st of those first lines in its place, and same for other lines … (using bash)
To be more precise, I want a script like the following:
#!/bin/bash
while :
do
echo "line1"
echo "line2"
echo "line3"
echo "line4"
# without using clear cmd, next cycle line1 should be printed
# in line1 place not in a new line , and same for other lines
done
Best Answer
On terminals that support it, you can use
tput sc
to save the cursor position andtput rc
to restore it:You can save those escape sequences in a variable to avoid having to invoke
tput
every time:On the rare terminals that don't support it, you can always use cursor positioning sequences,
See the
terminfo
man page in section 5 (if your system ships with ncurses) for more details.