It’s certainly no bad habit to handle spaces in scripts preemptively, and obviously they do occur in the wild. Quotes from ls output do not get piped to other commands. I had to look that up myself right now, because it has been quite a while since it mattered to me.
$ touch 'file with spaces in name'
$ ls
'file with spaces in name'
$ ls | cat
file with spaces in name
$
Looking through some scripts I wrote back in the day, I seem to like to use ls -1
in scripts. I guess that reduces ambiguity on what the separator is.
Heed the warning ;-)
Jk. It’s not black magic. Just do as AlpacaChariot said. You might want to read up on it a bit https://www.shell-tips.com/bash/environment-variables/