(no title)
yokohummer7 | 5 years ago
I thought the reason was to aid shell scripts that assumed no whitespaces in file names, wasn't it? Also, I believe I've seen single quotes when using `ls` on a terminal, so the behavior is not only for `!isatty()`.
vbezhenar|5 years ago
It wouldn't help shell scripts that assumed no whitespaces in file names anyway. You would get something like "'a", "b'", "c", "d" tokens which make no sense anyway.
The only sane way to iterate over files that I'm aware of is to use something like
But that's bashism...bonoboTP|5 years ago
Splitting on spaces, expanding asterisks, shell scripting is a minefield. You would basically never want any splitting to happen. Applications like reading a CSV by splitting using IFS are dirty hacks, that break with the slightest additional file parsing complexity (escapes, quoting etc).
In Python you can just do `os.listdir('.')` and it will actually do what you want. No 5 layers of "oh, actually" and "yes, but what if", which inevitably happen in threads discussing the simplest shell operations. It just works as intended. If you only want the files and not the directories, you can do `filter(os.path.isfile, os.listdir('.'))`.
There is no reason to use shell scripts for anything more complex than a few lines or for one-off interactive work.
cyphar|5 years ago
inopinatus|5 years ago
With bash or on GNU systems try
instead of echo, to obtain an escaped string.juped|5 years ago