I am trying to make a download progress meter with bash and I need to echo a percentage without making a newline and without concatenating to the last output line.
The output should replace the last output line in the terminal.
This is something you see when wget or curl downloads files. That's what I am trying to do, but I don't know how.
PS: echo is a buit-in for some shells that do not respect -n, so call the actual echo from whence/which it is found, or echo "....\c" works in ksh. Put a carriage return as first character and overwrite the line with enough characters to ensure all old data is gone. The cursor will rest to the right. You might want to pad a few spaces for added readability, as a blinking block cursor where you are focusing is just asking for an epileptic seizure.
printf can do a lot more than skipping the line feed, so that is a nice tool to adopt. It is a bit different, using it in shell not C/C++/JAVA, since without extra effort data are all character arrays.
Since the first string is a format string, % characters in it will be interpreted as formatting specifiers. %s means 'string'. So %s by itself will print things as they're given without a newline.
If you'd just done printf "mystring" it might do strange things if mystring has a % in it anywhere.