The count variable was not being updated because the while loops were
running in subshells created by the pipe operator. Variable assignments
in subshells don't affect the parent shell, causing count to remain 0.
Changes:
- list_files.sh: Changed from pipe to here-document with command
substitution to keep the while loop in the main shell
- list_files_bash.sh: Changed from pipe to process substitution using
< <(...) syntax to avoid subshell creation for the while loop
Both scripts now correctly display the total number of files found.
THis fix make the script fully POSIX-compliant for FreeBSD /bin/sh
Replace bash-specific `read -d ''` with tmpfile approach.
The -d option is not available in POSIX sh, causing the script
to fail on FreeBSD systems.
- Use tmpfile=$(mktemp) instead of null-delimited pipe
- Add trap for cleanup
- Remove -print0 and read -d '' options
- Add empty filename safety check
Fixes: read: Illegal option -d