A probe line prints the values a script is about to use. Parameter expansion can split a compact debug value into named parts.

Program

Play the script to choose a probe value and see the parsed fields.

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

probe="alpha:42"
name="${probe%%:*}"
count="${probe##*:}"
echo "probe:$name=$count"
#!/usr/bin/env bash

probe="beta:7"
name="${probe%%:*}"
count="${probe##*:}"
echo "probe:$name=$count"
  1. probe ← alpha:42

    3probe="alpha:42"4name="${probe%%:*}"
    values this stepalpha:42probe
  2. name ← alpha

    3probe="alpha:42"4name="${probe%%:*}"5count="${probe##*:}"
    values this stepalphanamealpha:42probe
  3. count ← 42

    4name="${probe%%:*}"5count="${probe##*:}"6echo "probe:$name=$count"
    values this step42countalpha:42probe
  4. echo "probe:$name=$count"

    5count="${probe##*:}"6echo "probe:$name=$count"
    outputprobe:alpha=42
    values this stepalphaname42count
  1. probe ← beta:7

    3probe="beta:7"4name="${probe%%:*}"
    values this stepbeta:7probe
  2. name ← beta

    3probe="beta:7"4name="${probe%%:*}"5count="${probe##*:}"
    values this stepbetanamebeta:7probe
  3. count ← 7

    4name="${probe%%:*}"5count="${probe##*:}"6echo "probe:$name=$count"
    values this step7countbeta:7probe
  4. echo "probe:$name=$count"

    5count="${probe##*:}"6echo "probe:$name=$count"
    outputprobe:beta=7
    values this stepbetaname7count
probe A probe is a temporary diagnostic line that exposes values during development.
prefix trim `${probe%%:*}` keeps the text before the first colon-shaped separator.
suffix trim `${probe##*:}` keeps the text after the last colon-shaped separator.