PsBash.Core
0.8.11
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package PsBash.Core --version 0.8.11
NuGet\Install-Package PsBash.Core -Version 0.8.11
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.11" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PsBash.Core" Version="0.8.11" />
<PackageReference Include="PsBash.Core" />
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.11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PsBash.Core, 0.8.11"
#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.11
#: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.11
#tool nuget:?package=PsBash.Core&version=0.8.11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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()andPsEmitter.Transpile()are thread-safeModuleExtractor.ExtractEmbedded()is thread-safe (uses file locking)- The parser uses
[ThreadStatic]for loop variable tracking
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.
-
net10.0
- Parlot (>= 1.5.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.