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:
- ramesh@dev-db ~> cat ps3.sh
- PS3="Select a day (1-4): "
- select i in mon tue wed exit
- do
- case $i in
- tue) echo "Tuesday";;
- wed) echo "Wednesday";;
- exit) exit;;
- esac
- done
- ramesh@dev-db ~> ./ps3.sh
- 2) tue
- 3) wed
- 4) exit
- Select a day (1-4): 1
- Monday
- Select a day (1-4): 4