In bash you can cast a command named clear
to clear all the screen commands.
And with echo
you can print whatever you want onscreen..
In my simple scripts I often have the need of print a percentage of what's being done with my commands..
So I could do something like..
echo "89%"
echo "90%"
echo "91%"
and so on..
what I hate is getting the screen full of percent updates...
89%
90%
91%
...
what I would like is to learn if there's a special character combination (eg. "\033[01;31m") that could be echoed with bash or php echo and tells the console "remove the last previous printed character.."
doing so by using something like: (php example)
echo str_repeat($neg_character, strlen($last_percentage_update_string));
echo $new_percentage_update_string;
I would get the new string printed at the exact position of the previous one without have the screen full of lines
Otherwise I look for an approach to do the same in other ways always using bash and php scripts (please include actual working examples at least with a debian9 console and php7)
tput cub 3
to move the cursor back by 3 columns without having to hardcode the sequence (andtput el
to erase the line). – Stéphane Chazelas Aug 23 '18 at 10:29\e
isnt portable 2. neither is\e[0E
ech
for erasure. And moving backwards by 3 positions has a gotcha, and two possible optimizations that full-screen programs tend to use. But both optimizations and erasure are overkill for simple current-line-only terminal stuff, when one follows that advice to use a fixed-width format specifier. Don't forget that100
is 3 digits long, by the way. (-: – JdeBP Aug 23 '18 at 16:53ncurses
PECL extension might do the trick for PHP scripts. – Stephen Kitt Aug 23 '18 at 19:08printf
implementation used. I imagine you have pointers to documentation I should read — would you care to share some? – Stephen Kitt Aug 23 '18 at 21:01