Hack 31. PS3 – Prompt used by “select” inside shell script

    You can define a custom prompt for the select loop inside a shell script, using the PS3 environment variable, as explained below.

    Shell script and output WITH PS3:

    1. ramesh@dev-db ~> cat ps3.sh
    2. PS3="Select a day (1-4): "
    3. select i in mon tue wed exit
    4. do
    5. case $i in
    6. tue) echo "Tuesday";;
    7. wed) echo "Wednesday";;
    8. exit) exit;;
    9. esac
    10. done
    11.  
    12. ramesh@dev-db ~> ./ps3.sh
    13. 2) tue
    14. 3) wed
    15. 4) exit
    16. Select a day (1-4): 1
    17. Monday
    18. Select a day (1-4): 4
    19.