Interview Prep/Shell Scripting/Arrays, conditionals and loops

What is the `select` statement used for?

BeginnerConceptArrays, conditionals and loops
Answer

select prints a numbered menu from a list and reads the user's choice into a variable, repeating until break.

PS3="Deploy to which environment? "
select env in dev staging prod quit; do
  case $env in
    quit) exit 0 ;;
    "")   echo "invalid choice" ;;
    *)    echo "deploying to $env"; break ;;
  esac
done

Useful for interactive runbooks; never in automation, which has no terminal.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arrays, conditionals and loops