-3

When I display a menu with select, tt displays something like this

1) Sample
2) Sample

I would like to turn it into

[01] Sample
[02] Sample

Is this possible?


(Original question for possible background)

This code was opensource and my friend of mine permit that any code within his repository can be copied or edited freely.

I'm having trouble editing this part

source /usr/local/sbin/back

_title ()
{
    clear
    printf "\nCUSTOMIZE WS STATUS\n\n"
}

_msg ()
{
    _title
    printf "\n"
    read -p "Your message : " message
}

_color ()
{
    _title
    printf "\nChoose color:\n\n"
    select option in blue red green;
    do
            if [[ -n ${REPLY//[0-9]/} ]] || [[ $REPLY -lt 1 ]] || [[ $REPLY -gt 13 ]]; then
                    printf "\nTry Again.\n" && sleep 2
            else
                    color=$option && printf "\nSelected Color: %s\n\n" "$color"
                    break
            fi
    done
}


_edit ()
{
    _msg
    _color
    _title
    cd /usr/local/bin/
    for wspy in ws-ssh.py ws-stunnel.py ws-ovpn.py
    do
        sed -i "s|^RESPONSE =.*|RESPONSE = 'HTTP/1.1 101 <font color="${color}">${message}</font>XXXXContent-Length: 1048576000000YYYY'|" $wspy
        sed -i 's|XXXX|\\r\\n|' $wspy
        sed -i 's|YYYY|\\r\\n\\r\\n|' $wspy
    done
    cd ~
    printf "\nDone, Please restart services via MENU to take effect.\n\n"
    return
}


_title
PS3="
Choose the number from options: "
select option in Edit Exit;
do
    case $option in
        Edit)
            _edit
            break
            ;;
        Exit)
            exit
            break
            ;;
        *)
            printf "Try Again." && sleep 2
            edit_ws
            break
            ;;
    esac
done
desertnaut
  • 57,590
  • 26
  • 140
  • 166
N O T E
  • 1
  • 2
  • 1
    I don't think there is a way to change how `select` formats its menu. It's rather distracting to post large amounts of (bad) code to ask a simple question like that. – tripleee Sep 23 '21 at 04:45
  • Tangentially, running `sed -i` on the same file repeatedly is particularly inelegant. See https://stackoverflow.com/questions/7657647/combining-two-sed-commands – tripleee Sep 23 '21 at 04:46
  • Modifying scripts in `/usr/local/bin` on the fly is rather brittle and inelegant, too. Probably those scripts should be rewritten to read a configuration file or something. – tripleee Sep 23 '21 at 04:50
  • Sorry i just want to ask if its possible, im having a hardtime figuring out the best solution to my problem. Btw thanks for the help. – N O T E Sep 23 '21 at 05:30

1 Answers1

0

Can I modify how select numbers its menu items?

No. It is not possible to change it. It is hardcoded to ) . From https://github.com/bminor/bash/blob/master/execute_cmd.c#L3134 :

#define RP_SPACE ") "
KamilCuk
  • 120,984
  • 8
  • 59
  • 111