The spaces without quotes cause problems with subsequent processing.Then the subsequent processing has bugs in it. Fix them.Can realpath or other utility return a quoted pathname?That would be extremely counterproductive. Do not look for kludges to work around your script's bugs. Fix the bugs instead. Start with <https://mywiki.wooledge.org/Quotes>.
You don't see a problem that ls produces quoted filenames and
realpath doesn't?