Interactive Prompts
Confirm Prompt
Choose a Decision
A confirmation prompt turns a short response into an explicit decision. The script should map the response before performing the action.
Program
Play the script to choose the confirmation response and see the resulting decision.
confirm_prompt_decision.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
response="y"
case "$response" in
y|Y) decision="apply" ;;
*) decision="preview" ;;
esac
echo "$response -> $decision"
#!/usr/bin/env bash
response="n"
case "$response" in
y|Y) decision="apply" ;;
*) decision="preview" ;;
esac
echo "$response -> $decision"
response ← y
3response="y"4case "$response" invalues this stepyresponsecase "$response" in
3response="y"4case "$response" in5 y|Y) decision="apply" ;;values this stepyresponsedecision ← apply
4case "$response" in5 y|Y) decision="apply" ;;6 *) decision="preview" ;;values this stepapplydecisionecho "$response -> $decision"
7esac8echo "$response -> $decision"outputy -> applyvalues this stepyresponseapplydecision
response ← n
3response="n"4case "$response" invalues this stepnresponsecase "$response" in
3response="n"4case "$response" in5 y|Y) decision="apply" ;;values this stepnresponsedecision ← preview
5 y|Y) decision="apply" ;;6 *) decision="preview" ;;7esacvalues this steppreviewdecisionecho "$response -> $decision"
7esac8echo "$response -> $decision"outputn -> previewvalues this stepnresponsepreviewdecision
confirmation
A confirmation asks the user to approve or decline an action.
case mapping
`case` maps a small set of responses to named decisions.
safe default
Responses outside the approved branch should choose the safer decision.