Process unusual filenames safely in a shell pipeline

8 steps · about 2 h 40 min · Intermediate

  1. Recognize unsafe filename expansion (guide, ShellCheck Wiki, 24 min)

    See how unquoted expansion splits and expands pathname data before a command receives it.

  2. Emit paths from a standards-based traversal (reference, The Open Group Base Specifications, 18 min)

    Understand the portable find expression model before adding implementation-specific null output.

  3. Protect filenames that begin with a dash (guide, ShellCheck Wiki, 18 min)

    Use an explicit path prefix or option boundary so a pathname cannot be interpreted as a command option.

  4. Quote shell expansions correctly (guide, GNU Bash manual, 22 min)

    Prevent word splitting, glob expansion and syntax interpretation when a pathname becomes an argument.

  5. Use option boundaries and target directories (guide, GNU Coreutils manual, 18 min)

    Keep a leading dash in a filename from becoming an option and make multi-file destinations explicit.

  6. Batch arguments within system limits (reference, The Open Group Base Specifications, 18 min)

    Use the standard utility model to stay inside argument-size limits and interpret exit behavior.

  7. Bound parallel file processing (reference, GNU Parallel documentation, 20 min)

    Add concurrency only with an explicit limit and a command safe to run independently.

  8. Review traversal and word-splitting hazards (guide, ShellCheck Wiki, 22 min)

    Use a static-analysis warning to identify loops that break unusual names and hide command failures.