5 ms·
> it's more unix than unix. Would you please elaborate what exactly do you mean by this?
by paskozdilar 5y ago
> it's more unix than unix.
Would you please elaborate what exactly do you mean by this?
- dale_glass 5y agoPowershell improves on Unix commands being based on text streams, and makes them based on objects. Which means you're pretty much never extracting stuff with cut and awk, and instead can just get whatever field you want. Eg: C:\Windows> Get-AuthenticodeSignature .\explorer.exe Directory: C:\Windows SignerCertificate Status StatusMessage Path ----------------- ------ ------------- ---- BBD2C438000344F439BFDFE5ABAC3223357CD67F Valid Signature verified. explorer.exe C:\Windows> (Get-AuthenticodeSignature .\explorer.exe).SignerCertificate Thumbprint Subject EnhancedKeyUsageList ---------- ------- -------------------- BBD2C438000344F439BFDFE5ABAC3223357CD67F CN=Microsoft Window… {Windows System Component Verification, Code Signing} C:\Windows> (Get-AuthenticodeSignature .\explorer.exe).SignerCertificate.Subject CN=Microsoft Windows, O=Microsoft Corporation, L=Redmond, S=Washington, C=US C:\Windows> This of course works with pipes: C:\Windows> Get-ChildItem . | Where-Object { $_.Length -gt 1000000 } | Sort-Object Length Directory: C:\Windows Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 8/11/2021 1:56 AM 1075712 HelpPane.exe -a--- 1/15/2018 12:40 PM 2856800 RtlExUpd.dll -a--- 4/25/2022 1:17 PM 5122632 explorer.exe Isn't that awesome? One of the nice things about it is that you can add stuff easily. You don't have to worry that every script that parses the output of your command will now break because you added an extra column or added extra functionality.
- majkinetor 5y agoYes it is. Its not awesome however to write Where-Object and Foreach-Object instead ? and %. It really turns one down. I can understand fanboyism for not using other aliases but those 2 are special and not using them brings the wrong picture about the pwsh.
- paskozdilar 5y ago> Powershell improves on Unix commands being based on text streams, and makes them based on objects I assume this means that PowerShell is deeply integrated with the .NET ecosystem? I don't like .NET very much, so that's a downside for me. One of the reasons I use Bash is the decades-old ecosystem of various utilities people have written. Can PowerShell use the same CLI utilities as Bash, and do the plain-old-text-stream processing pipelines like Bash, or is it .NET objects only?
- majkinetor 5y ago> I don't like .NET very much, so that's a downside for me. LOL. So arbitrary... do you like java vm or python? > Can PowerShell use the same CLI utilities as Bash, and do the plain-old-text-stream processing pipelines like Bash, or is it .NET objects only? Sure. Even better, it can convert wall of text into array of lines on the fly :) You should forget about parsing text in shell though. Because it sux and we know better now. Parsing text in pwsh is once-a-year thing.
- deleted 4y ago[deleted]
- paskozdilar 4y agoYeah? Well, you know, that's just, like, uh, your opinion, man.
- majkinetor 4y agoYours is not even opinion. You need to put some logic behind it man :) As for me, I will keep my Decade-And-More-Old-And-Still-Shiny-Shell-With-Objects-And-Stuff to myself :)
- paskozdilar 4y agoI don't think I need to "put some logic behind" not liking .NET, same as I dont need to put some logic behind not liking Java. It just sux and we know better now :) Also good luck with your emacs pinky. :) :) :) :D :D :D :) :) :^)
- inkyoto 4y ago> Isn't that awesome? It depends. In a world where commands produce, expect and consume well defined and highly structured data streams, it is actually great. It works well in Windows but only because scripting as the concept is relatively new to the Windows world. In UNIX, however, it is usually a mess and data extraction using the PowerShell approach would almost never work due spurious characters appearing in the output of a command (for any reason, really) as the UNIX style is precisely this: «cobble things together, use a sledgehammer to make everything work and move on. If it ain't broken then don't fix it». This is why running the output through a «sed» and searching for stable string patterns to cut interesting parts out and then (optionally) running them through cut/awk/et al is the Swiss army knife. Life has become somewhat easier recently with the advent and more widespread use of JSON, YAML (and to a certain extent XML before) as we now have jq, yq, dasel, mlr (Miller), xmlto etc – to capture, for instance, the JSON formatted output and do something with it just in the same way it is possible in PowerShell whilst also retaining the extensibility (see below) without having to rely on the availability of the source code of the producing utility/app. > One of the nice things about it is that you can add stuff easily. You don't have to worry that every script that parses the output of your command will now break because you added an extra column or added extra functionality. You can only add stuff easily if you control (own) the producer of the data stream. If the producer is a third party provided script/app you don't have the source code for, I believe you still have the same breakage problem, however PowerShell experts might want to chime in and correct me.
- dale_glass 4y ago> In UNIX, however, it is usually a mess and data extraction using the PowerShell approach would almost never work due spurious characters appearing in the output of a command Where would they come from? > (for any reason, really) as the UNIX style is precisely this: «cobble things together, use a sledgehammer to make everything work and move on. If it ain't broken then don't fix it». This is why running the output through a «sed» and searching for stable string patterns to cut interesting parts out and then (optionally) running them through cut/awk/et al is the Swiss army knife. If you're doing that a lot, the code tends to be fragile. If you use cut for instance, it breaks the second the data you're working it changes. Program decided column needs to be 5 characters wider? Now the stuff you're looking for is not there anymore. That's how you end up with "ifconfig is old, everyone switch to ip now". At some point a program's output may be parsed by so much stuff that any change risks breaking something, and it forces it to remain static for eternity. > You can only add stuff easily if you control (own) the producer of the data stream. If the producer is a third party provided script/app you don't have the source code for, I believe you still have the same breakage problem, however PowerShell experts might want to chime in and correct me. No, my point is that the producer is free to improve without risking the consumers. If your command that produced IPv4 addresses adds support for IPv6, it doesn't suddenly break every script that relies on precise lengths, line numbers and columns. You can also take somebody else's returned data and add extra stuff to it if you want to, just like you could take a bunch of JSON and modify it.
- jiggawatts 4y agoIf I wasn’t on mobile I would dig up some excellent articles on the topic, so please excuse the too brief summary: The core concept of the UNIX philosophy is that each tool should do one thing, and then you can compose them. In practice this doesn’t work because of the physical constraints of the small machines used back in the day when UNIX was developed. The original shell concept used plain byte or char streams, which are too primitive. The end result is that every tool has to do parsing and serialisation. Worse, they pretty print by default, losing the structure and making subsequent steps fragile. So for example, Visual Studio crashes if your Git version is “wrong” because it’s trying and failing to parse the output text. Similarly if you ask UNIX people to solve simple problems like “stop all processes run by ‘Ash’”, they’ll reach for grep and accidentally stop every bash process also. In PowerShell the commands don’t parse. They don’t serialise. They don’t pretty print. They don’t sort, filter, group, export, or import. Instead there are dedicated, single-purpose commands for those functions that compose elegantly. This is the UNIX philosophy, and PowerShell does it more than bash.
- majkinetor 4y agoAmen to that!