On Sat, Jun 28, 2025 at 18:28:31 -0400, Eben King wrote: > A while back I wrote a script to take the output of dd and make a graph of > the transfer rate. It worked, but since it scrolls up I wasn't happy with > it. > > In a bash script, I'm trying to use tput commands to delete column 1 (tput > cup $row 1 && tput el1), scoot the rest of the line left, then draw along > the right edge (echo -n). Step 2 is proving problematic, as in I don't know > how to do it. Is there another way? Thanks.
Are you doing a two-dimensional grid, or just a single line of text which is continually replaced? A single line is extremely simple: you write a CR (\r) character to move the cursor to the start of the line, and then you rewrite the entire line of text, with space padding at the end if necessary. No tput is even needed, if you use the space padding. You could use a "clear to end of line" command if you don't want to pad it. Here's a simple demonstration of a single line with space padding. We know that the output of $RANDOM is always between 1 and 5 characters (the highest number it can produce is 32767), so we take that into account when calculating the field width. ================================================== #!/bin/bash for ((i=0; i < 60; i++)); do text="There are $RANDOM things left." printf '\r%-28s' "$text" sleep 0.3s done echo ================================================== If you want to use tput output (erase to EOL, for example), the best way to do it is to run the tput command once up front and save its output in a variable. Then use the variable in your printing loop. Here's the same example using that technique: ================================================== #!/bin/bash el=$(tput el) for ((i=0; i < 60; i++)); do text="There are $RANDOM things left." printf '\r%s%s' "$text" "$el" sleep 0.3s done echo ==================================================