In one of my Bash scripts I have such code repeated twice:
find "$source_dir" -type f \
-iname "*.arw" \
-or -iname "*.cr2" \
-or -iname "*.crw" \
-or -iname "*.jpeg" \
-or -iname "*.jpg" \
-or -iname "*.nef" \
-or -iname "*.nrw" \
-or -iname "*.orf" \
-or -iname "*.pef" \
-or -iname "*.png" \
-or -iname "*.ptx" \
-or -iname "*.raf" \
-or -iname "*.raw" \
-or -iname "*.rw2" \
-or -iname "*.sr2" \
-or -iname "*.srf" \
-or -iname "*.srw" \
-or -iname "*.tif" \
-or -iname "*.tiff" \
-or -iname "*.x3f" | (
counter=0
while read image_file; do
(...)
There are two such find
commands both performed on different directories, but with exactly the same parameters. Results of each finds are processed in a different ways. I am convinced that it is possible to avoid code duplication here. Is there a way to wrap this find
command into a function that stores find results in some data structure? Such data structure must be passed to the subshell that iterates over its items. How can I achieve this?