Home > Back-end >  Can I modify how select numbers its menu items?
Can I modify how select numbers its menu items?

Time:09-23

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

CodePudding user response:

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 ") "
  • Related