Code Generation
Code Generation #4

Write a Bash script that watches a directory and prints a summary whenever a new file appears. The summary should include: filename, file size in human-readable form, file type (from the `file` command), and a SHA-256 hash. Handle the case where the directory doesn't exist yet.

9 models responded

o4-miniOpenAI
medium7.2

Judge: A solid bash script that handles the missing-directory case via inotifywait on the parent. Uses set -euo pipefail, proper quoting, and checks for required commands. Displays all four required summary fields. Main limitation: inotifywait is Linux-only (not available on macOS), and the script uses Linux-specific stat flags (-c '%s'). Race conditions with rapid file creation are partially handled but not robustly addressed.

Here’s a standalone Bash script. Save it as, say, watch_new_files.sh, make it executable (chmod +x), and then run it with the directory you want to watch as its only argument. It will wait for the dir...
openai/o4-mini · 2026-03-02
high7.0

Judge: Complete, well-structured bash script using inotifywait. Handles directory creation with mkdir -p, prints filename/size/type/SHA-256. Good error handling, proper quoting, command existence checks. However, relies on Linux-only inotifywait (not portable), verbose explanation padding, and lacks set -euo pipefail. The response itself is truncated in the explanation section but the script is complete.

This Bash script uses `inotifywait` to monitor a specified directory for new file creations. When a new file appears, it extracts its filename, size, type, and SHA-256 hash, then prints a formatted su...
gemini/gemini-2.5-flash · 2026-03-02
Claude OpusAnthropic
medium6.4

Judge: Handles directory creation, includes argument validation, has a human-readable size function with fallback. Response truncated but visible portions show reasonable bash scripting with proper quoting. Missing set -euo pipefail at the top. The cross-platform size detection (numfmt vs ls fallback) is a nice touch but the stat syntax shown is Linux-specific (not macOS compatible).

Here's a Bash script that watches a directory for new files and prints summaries: ```bash #!/bin/bash # Check if directory path is provided if [ $# -eq 0 ]; then echo "Usage: $0 <directory_path>...
anthropic/claude-opus-4-20250514 · 2026-03-01
Claude HaikuAnthropic
medium5.6

Judge: Truncated but shows strong bash fundamentals: set -euo pipefail, proper quoting, handles both macOS and Linux stat, human_readable_size function, checks for directory existence. The polling approach with tracking file is reasonable. Handles missing files. Cut off before SHA-256 hash section, but the visible code is production-quality bash.

# Directory Watcher Script Here's a comprehensive Bash script that watches a directory and prints summaries of new files: ```bash #!/bin/bash #######################################################...
anthropic/claude-haiku-4-5-20251001 · 2026-03-01
Claude SonnetAnthropic
medium5.4

Judge: Reasonable bash script structure with proper quoting and functions. Handles the directory-not-existing case with a polling loop. However, uses inotifywait (Linux-only) without mentioning portability, uses sha256sum instead of shasum (platform-dependent), and the response is truncated before the main watch loop. The dependency check function is a good practice. Missing set -euo pipefail.

Here's a Bash script that watches a directory and prints a summary when new files appear: ```bash #!/bin/bash # Default directory to watch (current directory if not specified) WATCH_DIR="${1:-.}" #...
anthropic/claude-sonnet-4-20250514 · 2026-03-01
Phi-4Microsoft
medium4.8

Judge: Meets hard constraints: bash script, handles missing directory (mkdir -p), displays all four required fields. Uses set -euo pipefail which is good practice. However, relies on inotifywait (Linux-specific, not available on macOS), uses Linux-specific stat flags, and moves files to a _processed directory which is a questionable design choice not requested. The globbing approach could miss files that appear between iterations.

### Helper: ```bash #!/bin/bash set -euo pipefail shopt -s nullglob globstar if [[ $# < 1 ]]; then echo 'Usage: watch_dir DIRECTORY' >&2 exit 1 fi DIRECTORY="$1" # Ensure the directory ex...
ollama/phi4 · 2026-03-01
GPT-4oOpenAI
high4.5

Judge: Functional script that handles directory creation and uses inotifywait for file watching. However, uses Linux-only tools (inotifywait, GNU stat, numfmt) without noting portability issues, lacks set -euo pipefail, and has quoting issues in the while-read loop that would break on filenames with spaces.

Certainly! Below is a Bash script that watches a specified directory for new files and prints a summary for each new file. The summary includes the filename, file size in a human-readable format, the ...
openai/gpt-4o · 2026-03-01
DeepSeek R1DeepSeek
medium4.4

Judge: The script is truncated mid-output, cutting off during the human-readable size calculation. What's visible shows good practices: command existence checks, directory wait loop, inotifywait usage, and quoting. However, the response is incomplete -- we can't verify it displays all required fields (filename, size, file type, SHA-256). Uses Linux-specific tools (inotifywait, numfmt) without noting macOS incompatibility. The truncation significantly limits the grade.

Here's a Bash script that monitors a directory and prints file summaries when new files appear: ```bash #!/usr/bin/env bash # Check for required commands for cmd in inotifywait stat file sha256sum; ...
deepseek/deepseek-reasoner · 2026-03-02
high2.4

Judge: Script has multiple issues: uses 'convert-size --si' which is not a standard utility, uses Linux-specific 'stat -c%s' (won't work on macOS), uses inotifywait without checking if directory exists first (the prompt specifically requires handling missing directory). The find command after inotifywait rescans all files rather than just new ones. No set -euo pipefail, no proper error handling.

Hard constraint failed: Must handle directory not existing yet -- script calls inotifywait on the directory without checking existence or waiting for it to be created.
```shell #!/bin/bash # Define a function to calculate the SHA-256 hash of a file calculate_sha256() { local filename="$1" local output=$(sha256sum "$filename") echo "${output%% *}" } # Define ...
ollama/llama3.1:8b · 2026-03-01