How to remove previous lines on bash?

I want to have a selector in a “case” menu, so I show the options:


<span style="color:#323232;">   1) option A
</span><span style="color:#323232;">   2) option B
</span><span style="color:#323232;">   3) option C
</span>

Then read the choice (let’s say it’s B), remove the previous menu and show this instead:


<span style="color:#323232;">   1) option A
</span><span style="color:#323232;"> » 2) option B
</span><span style="color:#323232;">   3) option C
</span>

How can I do this? I know we can remove the current line with echo -ne “r”, but I have no idea of how to do it with several

smpl,
@smpl@discuss.tchncs.de avatar

It doesn’t look to me like you want to remove lines. It looks like you want to move the cursor to a position and write a character.

You would probably want to move up two rows to column one and print the marker like this E[2F». If you want to delete option B and C and write them again it’ll be something like this echo -e “E[2FE[2K» 2) option BnE[2K 3) option C”.

See more in man console_codes

Also see the tput and terminfo manpages. You find the capabilities in terminfo and you use them with tput, like fx. moving the cursor to row 10 column 10 with tput cup 10 10, where cup is described in the terminfo manpage.

smpl,
@smpl@discuss.tchncs.de avatar

You can save and restore the cursor too with s and u , so that your example could be done from an interactive terminal like this.


<span style="color:#323232;">$ echo -en "  1) option An  2) option Bn  3) option CnE[s"
</span><span style="color:#323232;">  1) option A
</span><span style="color:#323232;">» 2) option B
</span><span style="color:#323232;">  3) option C
</span><span style="color:#323232;">$ echo -en "E[3F»E[uE[2K"
</span>
adchevrier,

With ‘clear’?

Moshpirit,
@Moshpirit@lemmy.world avatar

clear wipes the whole console, I prefer to keep the previous lines, and only remove some of them

  • All
  • Subscribed
  • Moderated
  • Favorites
  • bash@lemmy.ml
  • DreamBathrooms
  • everett
  • InstantRegret
  • magazineikmin
  • thenastyranch
  • rosin
  • GTA5RPClips
  • Durango
  • Youngstown
  • slotface
  • khanakhh
  • kavyap
  • ngwrru68w68
  • tacticalgear
  • JUstTest
  • osvaldo12
  • tester
  • cubers
  • cisconetworking
  • mdbf
  • ethstaker
  • modclub
  • Leos
  • anitta
  • normalnudes
  • megavids
  • provamag3
  • lostlight
  • All magazines