Shell scripts often combine variables with external tools. This example models a grep command and its selected match so the replay stays deterministic.

Program

Play the script to choose the pattern and see the command text and matched log line.

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

pattern="error"
command="grep '$pattern' app.log"
case "$pattern" in
    error) match="error db" ;;
    warn) match="warn cache" ;;
esac
echo "$command -> $match"
#!/usr/bin/env bash

pattern="warn"
command="grep '$pattern' app.log"
case "$pattern" in
    error) match="error db" ;;
    warn) match="warn cache" ;;
esac
echo "$command -> $match"
  1. pattern ← error

    3pattern="error"4command="grep '$pattern' app.log"
    values this steperrorpattern
  2. command ← grep 'error' app.log

    3pattern="error"4command="grep '$pattern' app.log"5case "$pattern" in
    values this stepgrep 'error' app.logcommanderrorpattern
  3. case "$pattern" in

    4command="grep '$pattern' app.log"5case "$pattern" in6    error) match="error db" ;;
    values this steperrorpattern
  4. match ← error db

    5case "$pattern" in6    error) match="error db" ;;7    warn) match="warn cache" ;;
    values this steperror dbmatch
  5. echo "$command -> $match"

    8esac9echo "$command -> $match"
    outputgrep 'error' app.log -> error db
    values this stepgrep 'error' app.logcommanderror dbmatch
  1. pattern ← warn

    3pattern="warn"4command="grep '$pattern' app.log"
    values this stepwarnpattern
  2. command ← grep 'warn' app.log

    3pattern="warn"4command="grep '$pattern' app.log"5case "$pattern" in
    values this stepgrep 'warn' app.logcommandwarnpattern
  3. case "$pattern" in

    4command="grep '$pattern' app.log"5case "$pattern" in6    error) match="error db" ;;
    values this stepwarnpattern
  4. match ← warn cache

    6    error) match="error db" ;;7    warn) match="warn cache" ;;8esac
    values this stepwarn cachematch
  5. echo "$command -> $match"

    8esac9echo "$command -> $match"
    outputgrep 'warn' app.log -> warn cache
    values this stepgrep 'warn' app.logcommandwarn cachematch
tool command A script can build the command text from shell variables.
grep `grep` filters text by matching a pattern.
deterministic replay The lesson models the tool output so static replay is stable everywhere.