0

I am creating a menu in a script (#!/bin/bash), and it works as I needed:

PS3='[ menu ] choose partition tool:' options=("fdisk" "cfdisk" "continue") select opt in "${options[@]}" do case $opt in "fdisk") fdisk /dev/sda ;; "cfdisk") cfdisk ;; "continue") break ;; *) echo "invalid option $REPLY" ;; esac done 

this is the result on screen:

1) fdisk 2) cfdisk 3) continue [ menu ] choose partition tool: 

how can I transform the layout like this (?):

[ menu ] choose partition tool (1) fdisk (2) cfdisk (3) continue: 

in a nutshell, I know that it is enough to write the options in PS3= like this: PS3='[ menu ] choose partition tool (1) fdisk (2) cfdisk (3) continue:' but I want to know how not to bring up the options list (up on description).

    1 Answer 1

    2

    You have to write the code for your custom version of select yourself. Something like this might work:

    #!/bin/bash # PS3='[ menu ] choose partition tool:' options=('fdisk' 'cfdisk' 'continue') while : do printf '%s' "$PS3" for ((i = 0; i < ${#options[@]}; i++)) do printf ' (%d) %s' $((i+1)) "${options[i]}" done read -p ': ' opt case "$opt" in 1|"fdisk") fdisk /dev/sda ;; 2|"cfdisk") cfdisk ;; 3|"continue") break ;; *) echo "invalid option $opt" ;; esac done 
    1
    • exactly wath I need and work, with my current skills (they are limited to simple commands and simple combinations, the rest is copy and paste around the Internet) I would not have known how to build it, but I understood why: select is just an premaded default menu, and if I wanted to change it i would basically have to change the kernel syntax (or something like that). here my script (work in progress): github.com/70V07/vmaib.git ─ EDIT: I re-comment why have changed the link due to changed the name of the script, sorry if annoying, not my intention; and ty again.CommentedMay 10, 2022 at 15:29

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.