PsBash.Core 0.8.20

dotnet add package PsBash.Core --version 0.8.20
                    
NuGet\Install-Package PsBash.Core -Version 0.8.20
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PsBash.Core" Version="0.8.20" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PsBash.Core" Version="0.8.20" />
                    
Directory.Packages.props
<PackageReference Include="PsBash.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PsBash.Core --version 0.8.20
                    
#r "nuget: PsBash.Core, 0.8.20"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PsBash.Core@0.8.20
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PsBash.Core&version=0.8.20
                    
Install as a Cake Addin
#tool nuget:?package=PsBash.Core&version=0.8.20
                    
Install as a Cake Tool

PsBash.Core

Bash-to-PowerShell transpiler library. Parses bash commands into an AST and emits equivalent PowerShell.

Quick Start

using PsBash.Core.Transpiler;
using PsBash.Core.Runtime;

// Transpile a bash command to PowerShell
string ps = BashTranspiler.Transpile("echo hello | grep -i 'world' | head -n 5");
// Result: "echo hello | Invoke-BashGrep -i 'world' | Invoke-BashHead -n 5"

// Extract the runtime module (needed for Invoke-Bash* functions)
string modulePath = ModuleExtractor.ExtractEmbedded();
// Load into your pwsh session: Import-Module $modulePath

Architecture

bash input --> BashLexer --> BashParser --> PsEmitter --> PowerShell string
  • BashLexer: Tokenizes bash input into typed tokens
  • BashParser: Recursive-descent parser producing an AST (based on Oils/OSH syntax.asdl)
  • PsEmitter: Walks the AST and emits PowerShell, mapping bash commands to Invoke-Bash* runtime functions

API Reference

BashTranspiler (recommended entry point)

// Transpile bash to PowerShell. Throws ParseException on invalid input.
string ps = BashTranspiler.Transpile("ls -la | grep '.txt'");

PsEmitter (lower-level access)

// Transpile with null return on parse failure (no exception)
string? ps = PsEmitter.Transpile("echo hello");

// Parse then emit separately (for AST inspection)
Command? ast = BashParser.Parse("echo hello");
string ps = PsEmitter.Emit(ast);

ModuleExtractor (runtime setup)

// Extract the embedded PsBash PowerShell module to a temp directory.
// Returns path to PsBash.psd1. Thread-safe, cached by assembly version.
string psd1Path = ModuleExtractor.ExtractEmbedded();

BashParser + AST (for custom processing)

using PsBash.Core.Parser;
using PsBash.Core.Parser.Ast;

Command? ast = BashParser.Parse("echo hello | wc -l");
// ast is Command.Pipeline with two Command.Simple children

Runtime Module

The transpiler emits calls to Invoke-Bash* functions (e.g., Invoke-BashGrep, Invoke-BashHead). These are provided by the embedded PowerShell module. Extract it once per session:

string modulePath = ModuleExtractor.ExtractEmbedded();
// Then in PowerShell: Import-Module $modulePath

Thread Safety

  • BashTranspiler.Transpile() and PsEmitter.Transpile() are thread-safe
  • ModuleExtractor.ExtractEmbedded() is thread-safe (uses file locking)
  • The parser uses [ThreadStatic] for loop variable tracking
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.8.20 93 4/22/2026
0.8.19 96 4/22/2026
0.8.18 89 4/22/2026
0.8.17 100 4/21/2026
0.8.16 90 4/21/2026
0.8.14 95 4/20/2026
0.8.12 101 4/16/2026
0.8.11 93 4/16/2026