Use [
code] around your code snippets for better readability.
Quote:
Originally Posted by fritz1968
for file in $(find -name "$fileExt" )
|
Unfortunately, no, this won’t work. You can try doing this:
Code:
find -name "$fileExt" | while read file; do
but even that will fail if any of the file contains a new line character. If I ever need to use find in such a way, I end up implementing it’s functionality in shell myself, i.e. something along the lines of:
Code:
handle_dir() {
for entry in "$1/"*; do
if [ -d "$entry" ]; then
handle_dir "$entry"
elif [ -f "$entry" ]; then
handle_file "$entry"
else
echo "$entry: not a regular file or directory, skipping" >&2
fi
done
}
hanadle_file() {
: … do what you need …
}
PS. Quote variables consistently and use ‘--’ to separate arguments from file names. For example:
Code:
mv -- "$file" "$dPath"
# NOT: mv "$file" "$dPath"