Hacker News new | ask | show | jobs
by jamesgeck0 2606 days ago
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.

1 comments

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"