Bash & Shell Scripting (50 Qs)•Part 3: Advanced Text Processing & Production Internals (Senior / Lead)
Building Interactive CLI Prompts: Colored terminal output, menus (`select`), and silent input (`read -s`).
senior LevelCode ExampleCLI
In Simple Words: Creating polished interactive developer tools:
bash
#!/usr/bin/env bash
# ANSI Color Palettes
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
echo -e "${CYAN}=== Production Deployment CLI ===${NC}"
# Silent Password Prompt (no echo on screen)
read -rsp "Enter API Secret: " SECRET
echo ""
# Interactive Selection Menu
PS3="Select Target Cluster: "
options=("US-East (Primary)" "EU-West (Failover)" "Staging" "Cancel")
select opt in "${options[@]}"; do
case $opt in
"US-East (Primary)") echo -e "${GREEN}Deploying to US-East...${NC}"; break ;;
"EU-West (Failover)") echo -e "${GREEN}Deploying to EU-West...${NC}"; break ;;
"Cancel") exit 0 ;;
*) echo -e "${RED}Invalid option${NC}" ;;
esac
done