Scripts often receive dates from arguments or configuration. A lightweight format check catches obvious mistakes before the value reaches a file name or command.

Program

Play the script to choose a date string and see whether it passes the shape check.

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

run_date="2026-06-01"
if [[ "$run_date" == ????-??-?? ]]; then
    status="iso-date"
else
    status="bad-date"
fi
echo "$run_date:$status"
#!/usr/bin/env bash

run_date="06/01/2026"
if [[ "$run_date" == ????-??-?? ]]; then
    status="iso-date"
else
    status="bad-date"
fi
echo "$run_date:$status"
  1. run_date ← 2026-06-01

    3run_date="2026-06-01"4if [[ "$run_date" == ????-??-?? ]]; then
    values this step2026-06-01run_date
  2. if [[ "$run_date" == ????-??-?? ]]; then

    3run_date="2026-06-01"4if [[ "$run_date" == ????-??-?? ]]; then5    status="iso-date"
    values this step2026-06-01run_date
  3. status ← iso-date

    4if [[ "$run_date" == ????-??-?? ]]; then5    status="iso-date"6else
    values this stepiso-datestatus
  4. echo "$run_date:$status"

    8fi9echo "$run_date:$status"
    output2026-06-01:iso-date
    values this step2026-06-01run_dateiso-datestatus
  1. run_date ← 06/01/2026

    3run_date="06/01/2026"4if [[ "$run_date" == ????-??-?? ]]; then
    values this step06/01/2026run_date
  2. if [[ "$run_date" == ????-??-?? ]]; then

    3run_date="06/01/2026"4if [[ "$run_date" == ????-??-?? ]]; then5    status="iso-date"
    values this step06/01/2026run_date
  3. status ← bad-date

    6else7    status="bad-date"8fi
    values this stepbad-datestatus
  4. echo "$run_date:$status"

    8fi9echo "$run_date:$status"
    output06/01/2026:bad-date
    values this step06/01/2026run_datebad-datestatus
ISO date `YYYY-MM-DD` is easy to sort and compare as text.
shape check A shape check catches values that are plainly not in the expected format.
input boundary Validate date text at the boundary before building paths or commands.