On 15 Sep 2022, at 17:34, zzapper wrote: > > I suppose I should be testing the filename before passing it to the expansion > > if [[ $f =~ '.jpg|gif|png|jpeg' ]] ;then echo 'ok' ;else echo 'nok' ;fi That’s how I’d approach it. Also make sure to check that the new file name doesn’t exist. A common workaround to trying to name a file the same as an existing file is to add a numerical suffix. Then you need to check if there’s already a file/some files with numerical suffixes and figure out what the next suffix needs to be. One example I saw was to start with N=1, then keep incrementing that counter until file_s_${N} doesn’t exist. Anyway, if you need help overthinking stuff I’ll be around. Alex