|
|
|
|
|
by matheweis
3274 days ago
|
|
ls | while read file; do echo "$file"; done ... works better for the easy edge cases, but still probably has some issues. Personally I think klodolph called it; once you get into anything that has a few interesting edge cases bash becomes pretty unwieldy. |
|
This works fine with spaces and other strange characters, no need to come up with more complicated ways.
If you must use find, the correct way is really tricky and uses obscure bash features like settings IFS to the empty string to split on null bytes and process substitution so that the loop doesn't run in a subshell (which would prevent it from modifying variables in the current environment):
while IFS= read -r -d '' file; do ... done < <(find /tmp -type f -print0)
See http://mywiki.wooledge.org/BashFAQ/020