Piping PowerShell Output Into Bash

With Windows 10, you can install Bash on Windows. Cool, right? Having Bash on Windows goes a long way towards making Windows a more developer-friendly environment and opens a ton of doors. The one I’m going to show you today is more of a novelty than anything else, but maybe you’ll find something neat to do with it.

If you’ve been around PowerShell, you’re used to seeing the pipe character ( ) used to pass the output from one command into the input of another. What you can do now, kind of, is pass the output of a PowerShell command into the input of a Bash command. Here’s an example. Get ready for this biz.
Get-ChildItem c:\temp\demo | foreach-object { bash -c "echo $($_.Name) | awk /\.csv/" }

In my c:\temp\demo folder, I have three files, two of which are CSVs. In an attempt to be super inefficient, I am piping the files in that directory into a foreach-object loop and using Bash to tell me which ones end in .csv, using awk. This is hardly the best way to do this, but it gives you an idea of how you can start to intermingle these two shells.

Written on September 13, 2017