The accepted answer is not compliant with best practices -- it'll fail badly with filenames with spaces or newlines in their names. To do it right, if you have a find with -print0:
#!/bin/bash
data=( )
while IFS= read -r -d '' filename; do
data+=( "$filename" )
done < <(find ~ -iname '*.png' -print0)
By the way, you don't really need arrays for this at all -- or even find:
#!/bin/sh
# This version DOES NOT need bash
# function to run for all PNGs in a single directory
translate_all() {
for i in "${1:-$HOME}"/*.png; do
mogrify -crop 1024x794 "$i"
rm "${i%.png}-1.png"
mv "${i%.png}-0.png" "$i"
done
}
# function to run for all PNGs in a single directory and children thereof
translate_all_recursive() {
dir=${1:-$HOME}; dir=${d%/}
translate_all "$dir"
for d in "$dir"/*/; do
translate_all_recursive "$d"
done
done
# actually invoke the latter
translate_all_recursive
References:
~doesn't get expanded correctly so this can't be working at all as written here. And you don't need (or want)exporthere.find, so the values are no longer guaranteed to be equivalent to their literals. In short, the filenames it returns can simply be wrong.touch 'hello * world.png'in a non-empty directory, and see what this code does in result.findusage you still couldn't correctly handle filenames with spaces from this code. However, those are all quoting issues that shellcheck.net would find for you easily.exporthere, as arrays are not exported anyway.