How do you backspace the line you just wrote with bash and put a new one over its spot? I know it's possible, Aptitude (apt-get) use it for some of the updating stuff and it looks great.
$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.
The Linux kernel default lets Ctrl-Backspace generate BackSpace - this is sometimes useful as emergency escape, when you find you can only generate DELs. The left Alt key is sometimes called the Meta key, and by default the combinations AltL-X are bound to the symbol MetaX.
A non-quoted backslash ' \ ' is the Bash escape character. It preserves the literal value of the next character that follows, with the exception of newline .
Try this:
$ printf "12345678\rABC\n"
ABC45678
As you can see, outputting a carriage return moves the cursor to the beginning of the same line.
You can clear the line like this:
$ printf "12345678\r$(tput el)ABC\n"
ABC
Using tput
gives you a portable way to send control characters to the terminal. See man 5 terminfo
for a list of control codes. Typically, you'll want to save the sequence in a variable so you won't need to call an external utility repeatedly:
$ clear_eol=$(tput el)
$ printf "12345678\r${clear_eol}ABC\n"
ABC
It's not really clear to me what you want, but, depending on your terminal settings you can print ^H (control H) to the screen and that will back the cursor up one position.
Also note that some terminals have the ability to move the cursor to the beginning of the line, in which case you'd move to the beginning of the line, print enough spaces to overwrite the entire line (Usually available from $COLUMNS) and then print any message or whatever.
If you clarify exactly what you want and I can answer you I'll update my answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With