I have a script that parses file names into an array using the following method taken from a Q&A on SO:
unset ARGS
ARGID="1"
while IFS= read -r -d $'\0' FILE; do
ARGS[ARGID++]="$FILE"
done < <(find "$@" -type f -name '*.txt' -print0)
This works great and handles all types of filename variations perfectly. Sometimes, however, I will pass a non-existing file to the script, e.g:
$ findscript.sh existingfolder nonexistingfolder
find: `nonexistingfile': No such file or directory
...
Under normal circumstances I would have the script capture the exit code with something like RET=$?
and use it to decide how to proceed. This does not seem to work with the process substitution above.
What's the correct procedure in cases like this? How can I capture the return code? Are there other more suitable ways to determine if something went wrong in the substituted process?