It currently uses the command template "ls | grep -i -E '%s' | xargs ls"to generate the file list, but xargs by default uses arbitrary whitespace as the delimiter, so this breaks up file names with spaces. I suggest changing the last part to xargs -d '\n' ls, which will work better (it still doesn't protect you against file names with newlines in them...).