FDD-book/examples/part-01/ch03-a-gentle-introduction-to-unix/portability/list_files.sh
Edson Brandi 6e6dac94fe Add book companion files under examples/
Organize companion code and materials by book part:

  part-01/      Foundations
  part-02/      Kernel & driver fundamentals
  part-03/      Character & block devices
  part-04/      Networking & storage
  part-05/      Buses & advanced topics
  part-06/      Debugging & performance
  part-07/      Real-world drivers
  appendices/   Supplementary material
  README.md     Overview and build instructions
2026-04-25 16:51:00 +00:00

21 lines
545 B
Bash

#!/bin/sh
# list_files.sh - count files in home directory
#
# DELIBERATELY NAIVE: this version is the "naive approach that breaks"
# in the chapter's "Shell Portability" section. It counts a file with
# a newline in its name as two separate files. Compare with the
# _bash, _posix, and _exec variants in this directory.
set -eu
cd "${HOME}"
count=0
while IFS= read -r f; do
fname=${f#./}
echo "File found: '$fname'"
count=$((count + 1))
done << EOF
$(find . -maxdepth 1 -type f ! -name ".*" -print)
EOF
echo "Total files found: $count"