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.

response
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"
  1. response ← y

    3response="y"4case "$response" in
    values this stepyresponse
  2. case "$response" in

    3response="y"4case "$response" in5    y|Y) decision="apply" ;;
    values this stepyresponse
  3. decision ← apply

    4case "$response" in5    y|Y) decision="apply" ;;6    *) decision="preview" ;;
    values this stepapplydecision
  4. echo "$response -> $decision"

    7esac8echo "$response -> $decision"
    outputy -> apply
    values this stepyresponseapplydecision
  1. response ← n

    3response="n"4case "$response" in
    values this stepnresponse
  2. case "$response" in

    3response="n"4case "$response" in5    y|Y) decision="apply" ;;
    values this stepnresponse
  3. decision ← preview

    5    y|Y) decision="apply" ;;6    *) decision="preview" ;;7esac
    values this steppreviewdecision
  4. echo "$response -> $decision"

    7esac8echo "$response -> $decision"
    outputn -> preview
    values 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.