Shell Tool Integration
Grep Filter
Choose a Pattern
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.
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"
pattern ← error
3pattern="error"4command="grep '$pattern' app.log"values this steperrorpatterncommand ← grep 'error' app.log
3pattern="error"4command="grep '$pattern' app.log"5case "$pattern" invalues this stepgrep 'error' app.logcommanderrorpatterncase "$pattern" in
4command="grep '$pattern' app.log"5case "$pattern" in6 error) match="error db" ;;values this steperrorpatternmatch ← error db
5case "$pattern" in6 error) match="error db" ;;7 warn) match="warn cache" ;;values this steperror dbmatchecho "$command -> $match"
8esac9echo "$command -> $match"outputgrep 'error' app.log -> error dbvalues this stepgrep 'error' app.logcommanderror dbmatch
pattern ← warn
3pattern="warn"4command="grep '$pattern' app.log"values this stepwarnpatterncommand ← grep 'warn' app.log
3pattern="warn"4command="grep '$pattern' app.log"5case "$pattern" invalues this stepgrep 'warn' app.logcommandwarnpatterncase "$pattern" in
4command="grep '$pattern' app.log"5case "$pattern" in6 error) match="error db" ;;values this stepwarnpatternmatch ← warn cache
6 error) match="error db" ;;7 warn) match="warn cache" ;;8esacvalues this stepwarn cachematchecho "$command -> $match"
8esac9echo "$command -> $match"outputgrep 'warn' app.log -> warn cachevalues 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.