Problem Statement
What does the select statement do in bash?
Explanation
Select creates numbered interactive menu from list, prompting user to choose option. Syntax:
```bash
select VAR in option1 option2 option3; do
case $VAR in
option1) commands; break;;
option2) commands; break;;
*) echo "Invalid";;
esac
done
```
Displays numbered list, reads user input, sets VAR to selected value. Loop continues until break.
Customize prompt with PS3 variable: PS3="Choose option: " select VAR in opt1 opt2; do ... done. Selected index in $REPLY. Combine with case for handling selections. Break exits select loop, useful after processing choice.
Practical menu example:
```bash
PS3="Select operation: "
select op in "Backup" "Restore" "Exit"; do
case $op in
Backup) backup_function; break;;
Restore) restore_function; break;;
Exit) break;;
*) echo "Invalid option";;
esac
done
```
Select useful for interactive scripts, setup wizards, configuration tools, or any script requiring user choice from predefined options. Provides clean interface without manual menu implementation. Understanding select simplifies creating user-friendly interactive scripts.
