Skip to content

SC2044: find loop wiki suggestion has problem in specific case #3190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tbsmark86 opened this issue Apr 16, 2025 · 0 comments
Open

SC2044: find loop wiki suggestion has problem in specific case #3190

tbsmark86 opened this issue Apr 16, 2025 · 0 comments

Comments

@tbsmark86
Copy link

Hi! Sorry if this is not the correct place.

The proposed loop for find has a nasty problem try this:

while IFS= read -r -d '' file
do
  (( count++ ))
  cat - > /dev/null
done <   <(find /tmp -print0)
echo "$count"

I've stumbled on this in a real-world example where inside the for loop was some tar and ssh to copy files. Nut sure which process but somebody consumed some of the input leading to strange garbled file names being processed.

A safer solution could be:

while IFS= read -r -d '' file <&3
do
  (( count++ ))
done 3<   <(find /tmp -print0)
echo "$count"

But of course now if some process reads from 3 for whatever reason it's the same problem. Only a bit less likely.
Maybe you could update the wiki?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant