Linux Basic — Interactive Scripts
Interactive Scripts
Interactive scripts let humans provide input: credentials, choices, or configuration values. This chapter covers the canonical building blocks for robust, user-friendly prompts and validation.
What You Will Learn
- Prompting with
read(-p,-r,-s,-t,-n) - Reading lists into arrays and using
mapfile/readarray - Input-validation loops that retry and provide defaults
- The
selectstatement for simple menus - Option parsing for small interactive tools with
getopts - Implementing safe yes/no confirmations
Topics in This Chapter
| # | Topic | Description |
|---|---|---|
| 1 | read with Prompts | read -p/-r/-s/-t/-n and mapfile |
| 2 | Input Validation Loops | retry loops, defaults, sanitisation |
| 3 | select Statement | menu-driven choice built-in |
| 4 | getopts Option Parsing | POSIX-style short option parsing |
| 5 | yes/no Confirmation | canonical Y/N prompts with defaults |
| 6 | Practice Exercises | Hands-on tasks |
Interactive scripts should be forgiving: offer clear prompts, defaults, timeouts where appropriate, and sanitize everything before use.
Next → read with Prompts