Hacker News new | ask | show | jobs
by jtr_47 2606 days ago
I don't see this as a threat to any Unix like operating system. In my 20+ years in IT, Microsoft has had many years to perfect their command line experience, but never did. They have a long way to go in terms of Unix like features that are part of the command line ecosystem of Unix land.

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

9 comments

> cat somefile.txt | sort | uniq > output.txt,

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!

>Powershell is obscenely powerful, it is equal to anything Bash can do plus:

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.

Agreed - Since MS has open-sourced PowerShell, it really should get picked up and used by more folks in the Linux community - it seems like its mostly decades of bad blood preventing that, even though it's a clearly superior 21st century approach. My allegiance is to great tools, and I'm learning PowerShell b/c of this...
The concepts around Powershell are good. But the language is a nightmare and simple things like the short-circuit operator are completely broken.
If you use aliases then its not nightmare. Use aliases, they are the same as on linux and even better (you can deduce them from the full name by standard).

> 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.
Unfortunately, outputting the boolean result makes "and" rather useless. See https://github.com/PowerShell/PowerShell/issues/3241
my problem with powershell is that cmd.exe based workflows are not compatable, and it's workflows are sufficiently different from bash/cmd to make me avoid learning it. Why spend a few days learning pwsh if I can just use cmd now and move on to my next task.
Because even though you can do most things in cmd, it's just never been a very good tool? CMD is a bad tool that we learned to use b/c we had no choice (w/o loading an add-on scripting env of some kind). PowerShell has a learning curve, and I've delayed learning it for many years, but now is the time to do it, esp now that it's open-sourced and available on more and more Linux distros...
Yeah that's why I'm also still on cmd.exe.

Every time I've dove into Powershell, wow, impressed, but I have over 2 decades of experience with cmd.exe!

> When I can do this in windows (unix command line): cat somefile.txt | sort | uniq > output.txt

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.

WSL runs Linux binaries on the NT kernel. That command executes in bash on Windows with no modification.

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.

That's pretty neat! Will have to try that the next time I'm using Windows.

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!

In fact, you don't even need to be in bash - WSL also installs a Win32 binary bash.exe, that redirects to Bash inside your default Linux install (there can be several). Which means that you can do this in cmd:

   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"
"When I can do this in windows (unix command line): cat somefile.txt | sort | uniq > output.txt, then it'll become a threat"

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.txt
I would suggest you check out WSL (if you're running Win10, just install your favorite distro from the store).

Not 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.

Like this?

    me@thinkpad:~/
    $ cat somefile.txt | sort | uniq > output.txt

    me@thinkpad:~/
    $ uname -r
    4.4.0-17763-Microsoft
You can do that easily through WSL. (Powershell can do the equivalent too, but of course with different syntax)
Surely you jest. You can't possibly think that you can't do that in Windows.
That is some serious BS - PowerShell is better then any other shell now. Its literally designed by UNIX people. Even your example is now shorter in PS then in bash.