by jtr_47 · 7y ago · 0 comments
When I can do this in windows (unix command line): cat somefile.txt | sort | uniq > output.txt, then it'll become a threat. Otherwise, Microsoft should fork a version of GNU/Linux and port all of their apps and GUI. They need to stop trying, they had their chance but may never achieve equality when it comes to the Windows Vs. Unix/GNU-Linux command line.
This is my opinion and observation.
Peace
in cmd.exe
type somefile.txt | sort /unique > output.txt
or in powershell
type file.txt | sort -unique
Powershell is obscenely powerful, it is equal to anything Bash can do plus:
1. It sends objects instead of streams, so instead of relying on fixed width output and string splitting, you can specify which column(s) of output you want from a tool directly
2. It can pull data from all sources of sources, including databases, WMI, COM sources and more.
3. Fully plugged into automation for servers, rich auto-complete, and a native ecosystem that is designed to all work together.
4. It can call into .NET libraries
But even cmd.exe can handle outputting text and sorting it!
Yeah, modern shells should stop pretending that everything is text. That's ridiculous. Powershell is doing a good job here.
As for power, powershell is to weak compared to Python or Ruby, too few libraries and fancy stuff, at least on unices. Maybe it could compete with Racket, but Racket is a much nicer language IMHO.
> short-circuit operator are completely broken.
What do you mean ? This kind of thing ?:
> 0 -and (Write-Host 2)
False
> 1 -and (Write-Host 2)
2
False
Not typically used in PowerShell, its bash paradigm IMO. There are objects here, so we throw error objects mostly and combine lines differently.Every time I've dove into Powershell, wow, impressed, but I have over 2 decades of experience with cmd.exe!
There are a lot of responses of the form "you can do this similar command in WSL/PowerShell/etc.," where that similar command will not run on a standard Unix-based system. I think that misses half of the point. One of the reasons a lot of programmers use OS X is specifically because you don't need separate sets of commands for the desktop and Linux cloud server (obviously, Linux gets even closer).
It's been possible to do a lot of stuff from the Windows command line for a long time. The problem has been that to do so effectively, many teams have to maintain a .bat alongside the .sh that will be used in production.
The opposite also works. Powershell has had a Linux port for a bit now. There's no reason you couldn't use use Powershell scripts to deploy to Linux servers if you wanted to.
Based on the peer comments I was replying to, a lot of Windows developers aren't even aware of this ability (hence my comment).
Thanks for clarifying!
bash -c "cat somefile.txt | sort | uniq > output.txt"
Since bash handles pipes and redirection in this case, it preserves Unix semantics exactly. And since WSL can see all your filesystems (they're mounted under /mnt/c, /mnt/d etc), and bash.exe maps current working directory, this works in any directory.This is much more tedious when you have to specify paths, because they have to be mapped explicitly, much like cygpath in Cygwin:
bash -c "cat `wslpath -u 'C:\Temp\somefile.txt'` | sort | uniq > output.txt"I take it you haven't tried WSL in the last couple of years?
cat .\somefile.txt | sort | unique | add-content "sortfile.txt"
I mean really it's not that hard to learn the actual PS syntax instead of the aliases: get-content .\somefile.txt | sort-object | get-unique | add-content .\sortfile.txtNot only can you do operate your typical one-liners but if the package is basically command line driven you can just apt-get install it and go.
There is a remaining wart that I hit from time to time, if I have a git repo that I want to talk to both from the WSL window and from a Git Shell (Cygwin app), the line endings get tweaked. It can be managed but it is still annoying.
me@thinkpad:~/
$ cat somefile.txt | sort | uniq > output.txt
me@thinkpad:~/
$ uname -r
4.4.0-17763-Microsoft