select
shell builtinLinux/Unix
The select command is one of the most frequently used commands in Linux/Unix-like operating systems. select Create an interactive selection menu in the shell
Quick Reference
Command Name:
select
Category:
shell builtin
Platform:
Linux/Unix
Basic Usage:
select [options] [arguments]
Common Use Cases
Syntax
select name [in words ...]; do commands; done
Options
Variable | Description |
---|---|
PS3 |
The prompt string displayed for the select command (default is "#? ") |
REPLY |
Contains the number entered by the user |
name |
The variable that receives the selected item |
IFS |
Internal Field Separator (affects how the items are split) |
Examples
How to Use These Examples
The examples below show common ways to use the select
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
select option in "Option 1" "Option 2" "Option 3" "Quit"
do
case $option in
"Option 1")
echo "You selected Option 1"
;;
"Option 2")
echo "You selected Option 2"
;;
"Option 3")
echo "You selected Option 3"
;;
"Quit")
echo "Exiting..."
break
;;
*)
echo "Invalid option"
;;
esac
done