My bash-script looks as following:
echo "Description:" while [ $finishInput -eq 0 ]; do read tmp desc="$desc"$'\n'"$tmp" if [ -z "$tmp" ]; then finishInput="1" fi done echo -n "Maintainer:" read maintainer
It reads to the desc var until a empty line is passed. After that, i want to read in other stuff.
When executing my current script it looks like this:
Description: Line 1 Line 2 Maintainer:
I would like to overwrite the last empty line with the "Maintainer:".
I searched for a solution but only found suggestions which were like
echo -n "Old line" echo -e "\r new line"
which stays on the line and overwrites it. This is not possible in my case.
To overwrite the current standard output line (or parts of it) use \r (or \b .) The special character \r (carriage return) will return the caret to the beginning of the line, allowing you to overwrite it.
If you are executing a Bash script in your terminal and need to stop it before it exits on its own, you can use the Ctrl + C combination on your keyboard.
The > redirection is done by shell, not by echo . In fact, the shell does the redirection before the command is even started and by default shell will overwrite any file by that name if exists.
In your example you delete the text at the same line. When you want to return to the previous line use \e[1A
, and to clear that line, use \e[K
:
echo 'Old line' echo -e '\e[1A\e[Knew line'
When you want to go N
lines up, use \e[<N>A
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