this post was submitted on 28 Aug 2023
9 points (100.0% liked)

Bash

720 readers
7 users here now

Talk about the Bash Shell and Bash scripting

founded 4 years ago
MODERATORS
 

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

   1) option A
   2) option B
   3) option C

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

   1) option A
 » 2) option B
   3) option C

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

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 1 year ago

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.

$ echo -en "  1) option A\n  2) option B\n  3) option C\n\E[s"
  1) option A
» 2) option B
  3) option C
$ echo -en "\E[3F»\E[u\E[2K"