4 ms·
That's the problem with passing around unstructured text as opposed to data structures.
by adamnemecek 6y ago
That's the problem with passing around unstructured text as opposed to data structures.
- jeppesen-io 6y agoExactly
- avmich 6y agoCan you elaborate please? I'm curious.
- betaby 6y agoBasically most Unix utils outputs free text data and then one expected to parse/filter that free text to pipe to another util. Power shell tries to operate in 'objects' and not free text.
- adamnemecek 6y agoI'm well aware. I think the Unix approch might have worked back in the day, but it's kind of broken these days.
- TheOtherHobbes 6y agoBack in the day it was considered the only option for many applications. It seems very questionable to be living with a severe restriction from the 1970s in 2020. But... it can't be unbroken without breaking backward compatibility in all kinds of legacy code.
- adamnemecek 6y agoThe trick is to create an alternative that can coexist.
- stonogo 6y agoVMS had structured files in the 1970s. Plaintext streams were not considered the only option; this was a deliberate decision by the developers of unix because they regarded it as more flexible.
- avmich 6y agoMaybe we shouldn't use complex structures if we don't really need. Having e.g. special characters which can't happen in normal strings - only on boundaries - makes parsing simpler. At the same time we remove "hidden" layer of object organization, so whatever is seen in shell can be byte-for-byte transferred to another computer and processed there. I've seen arguments for object-oriented shells when we want to have more complex plumbing than traditional Unix shell piping, but not sure if those goals couldn't be achieved while remaining in text-only land.
- cma 6y agoFilenames can have newlines. If you had it as a string data structure you wouldn't have bad parsing assumptions people make like files contain no spaces (most realize they can), files contain no newlines (many don't know they can), a file named '-rf' doesn't ever exist in the current working directory (many people may not realize `rm *` may recursively forcibly delete lots of things under a directory).
- samatman 6y agohah, I made a related mistake once: I had intended to move something from `file` to `~file`, and moved it to `-file` instead. This breaks a remarkable number of things! I just deleted it from Finder, then remembered I could `rm '-file'`.
- eMSF 6y agoTyping those single quotes in a shell won't make any difference as far as rm is concerned (because it won't ever see them). However, some rm utilities are smart enough to remove files, even if they resemble non-existing options. For others, the idiom is (either) "rm -- -file" or (preferably) "rm ./-file" although you can combine the both of them.
- mr_toad 6y agoNewlines in file names screw up so many things (both on the command line and in visual output) that I think that anyone using them should just stop.
- bluedino 6y agoA good example is a naive shell script that tries to parse the output of ls
- Jtsummers 6y agoOf course, while it doesn't solve the entire problem, there are ASCII characters for things like "group separator", "record separator", and "file separator" that could be used for establishing structure in output. But they're not used often, and so we just parse plain text.
- jcranmer 6y agoAnd, of course, it's valid to use these characters in filenames because apparently the idea of making any filename invalid is anathema.