3 ms·
The thing you have to be really careful about is escaping. Compared to the Object Oriented PowerShell where every column is just an object property, strongly t
by jiggawatts 7y ago
The thing you have to be really careful about is escaping.
Compared to the Object Oriented PowerShell where every column is just an object property, strongly typed and everything, the string-based bash programming to me seems absolutely bonkers.
Like... what do you do if some text doesn't fit into the space available?
How do you handle Unicode?
What about simple escaping of names like O'Toole, embedded double quotes, leading or trailing spaces that are meaningful, embedded line feeds, etc...
Eventually you have to use a full parser, not a bunch of regexes. I've found that "eventually" to mean: almost immediately, even for supposedly simple problems.
Even seeming trivial things like correctly splitting up an X.500 name as seen in LDAP or PKI is deceptively difficult. Now, if it's a LDAP name that includes quotes embedded in a CSV... err... I don't even know where to begin.
- theamk 7y agoI found tab-separated files can get me pretty far. It can handle arbitrary length text, Unicode is no problem at all, leading/trailing spaces are preserved and so on. It is trivially convertible to name=value format, as long as you guarantee the "name" part is well-formed (usually the case). The only tricky parts are embedded line feeds and tabs, and those can be defeated with trivial escape schema, even something as simple as '\r', '\t', '\\'. Bash quoting also works. If you master the difference between "${x[@]}" and ${x[*]}, keep in mind order of expand / split all the time, and never forget the right kind of quotes, you can have a robust system which can handle arbitrary strings. But I would not recommend this to anyone.
- benibela 7y agoOr ASCII control characters No reason to use tabs, when there explicit group/record/unit separators
- majkinetor 7y agoTotally. In bash 99% of the time is lost in side effects. PowerShell makes everything possible in 3 lines of code.
- mickotron 7y agoYou try doing any reasonable data processing with PowerShell and it will use a lot of resources. You can accomplish a lot with awk. I was a PowerShell advocate but it still has a lot of rough edges which is disappointing. And is very verbose. Sometimes grep | awk can be incredibly succinct and fast.
- majkinetor 7y agoNot sure what you mean because it uses dot.net regex. Sure, its way more generally resource hungry then awk but again, it does tone of things. Its also good to know that you have that power ASAP on Windows and without any extra toolson *nix such as awk or jq or sed. I regularly handle 100MB files with Powershell regex , yeah, I wait few seconds here and there, but nothing except ripgrep handles this fast. Verbosity is nonsensical arugment for anything as you have alises. Bash is equally verbose if you use long parameter names.