Automation scripts are safer when they can show the planned action before applying it. A dry-run flag keeps that choice visible.

Program

Play the script to choose preview or apply mode and see the planned deployment action.

dry_run
dry_run_plan.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash

dry_run=1
target="staging"
if [ "$dry_run" -eq 1 ]; then
    action="preview"
else
    action="apply"
fi
plan="$action:$target"
echo "$plan"
#!/usr/bin/env bash

dry_run=0
target="staging"
if [ "$dry_run" -eq 1 ]; then
    action="preview"
else
    action="apply"
fi
plan="$action:$target"
echo "$plan"
  1. dry_run ← 1

    3dry_run=14target="staging"
    values this step1dry_run
  2. target ← staging

    3dry_run=14target="staging"5if [ "$dry_run" -eq 1 ]; then
    values this stepstagingtarget
  3. if [ "$dry_run" -eq 1 ]; then

    4target="staging"5if [ "$dry_run" -eq 1 ]; then6    action="preview"
    values this step1dry_run
  4. action ← preview

    5if [ "$dry_run" -eq 1 ]; then6    action="preview"7else
    values this steppreviewaction
  5. plan ← preview:staging

    9fi10plan="$action:$target"11echo "$plan"
    values this steppreview:stagingplanpreviewactionstagingtarget
  6. echo "$plan"

    10plan="$action:$target"11echo "$plan"
    outputpreview:staging
    values this steppreview:stagingplan
  1. dry_run ← 0

    3dry_run=04target="staging"
    values this step0dry_run
  2. target ← staging

    3dry_run=04target="staging"5if [ "$dry_run" -eq 1 ]; then
    values this stepstagingtarget
  3. if [ "$dry_run" -eq 1 ]; then

    4target="staging"5if [ "$dry_run" -eq 1 ]; then6    action="preview"
    values this step0dry_run
  4. action ← apply

    7else8    action="apply"9fi
    values this stepapplyaction
  5. plan ← apply:staging

    9fi10plan="$action:$target"11echo "$plan"
    values this stepapply:stagingplanapplyactionstagingtarget
  6. echo "$plan"

    10plan="$action:$target"11echo "$plan"
    outputapply:staging
    values this stepapply:stagingplan
dry run A dry run prints or records the action without applying side effects.
target Keeping the target in a variable makes the plan easy to review.
apply boundary The branch that would apply changes is explicit and testable.