Bash newline-counting practice kit — Yenra
Article: https://yenra.com/bash-shell-script-programming/
Requirements: Bash and wc. Tested with Git for Windows Bash 5.2.37.
Unzip into a new private directory. Open Bash and cd into the sample folder.
Run: bash count-lines.sh notes
Expected header: file<TAB>newlines
Expected rows: alpha.txt<TAB>2 and two\ words.txt<TAB>1 (one backslash before the space).
The tab characters align columns. Bash %q escapes filenames for display.
The script reads visible top-level .txt regular files, skips symbolic links,
does not recurse, and counts newline characters. An unterminated last line
contributes zero newlines. Files changing during a read are outside this example.
Run: bash -n count-lines.sh
Run: bash count-lines.sh missing
Then immediately run: printf 'status=%s\n' "$?"
Expected missing-directory status: 2. No files are deleted or rewritten.
Status 1 indicates a read failed. Status 0 includes an empty directory.
For a diagnostic trace: bash -x count-lines.sh notes
Review scripts before using them on your own data; trace output shows arguments.
