hey, nice job!
I've got three issues in my mind after a quick look - two aren't that big of a deal and one might cause unexpected results
1. less serious one is creating temp dir in current working directory - it will fail if temp dir exists on mkdir temp (but won't fail the whole script). mktemp -d may be more suitable in here
2. you may want to take a look at bash(1) manpage, specifically at shell builtin commands section set command (-e, -u and -o pipefail options)
3. the more serious one - filenames should be quoted, as they may contain spaces and this will cause weird behavior
other than this, it looks good!
I've got three issues in my mind after a quick look - two aren't that big of a deal and one might cause unexpected results
1. less serious one is creating temp dir in current working directory - it will fail if temp dir exists on mkdir temp (but won't fail the whole script). mktemp -d may be more suitable in here
2. you may want to take a look at bash(1) manpage, specifically at shell builtin commands section set command (-e, -u and -o pipefail options)
3. the more serious one - filenames should be quoted, as they may contain spaces and this will cause weird behavior
other than this, it looks good!