Bash <-> PowerShell Translator
Translate Bash one-liners to PowerShell and vice versa using a rules table.
Overview
Paste a Bash one-liner and get a PowerShell equivalent (or vice versa) using a rules table that covers the everyday cases - pipes, redirects, common commands, environment variables, file globbing, and the most-used flags for tools like grep, find, ls, and curl.
It's for developers who move between WSL, macOS, and Windows and keep tripping over the syntactic gulf. Reach for it when porting CI scripts to a new runner, sharing snippets with a teammate on a different shell, or quickly translating a Stack Overflow answer that's the wrong dialect.
How it works
The translator runs a pattern-matching pass over your input, swapping out tokens that have well-known equivalents - for example, grep becomes Select-String, cat becomes Get-Content, $VAR becomes $env:VAR, and 2>/dev/null becomes 2>$null. Pipes and quoting are preserved as-is where the two shells agree, and rewritten where they don't (PowerShell's pipeline passes objects, not text).
This isn't a full shell parser - it covers idiomatic one-liners, not nested subshells or arbitrarily complex command chains. The result is best read as a starting point, with manual review for anything beyond a single pipeline.
Examples
- Find files modified in the last day:
find . -type f -mtime -1Get-ChildItem -Recurse -File | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-1) } - Grep with line numbers:
grep -n "TODO" *.csSelect-String -Pattern "TODO" -Path *.cs - Environment variable export:
export DEBUG=true$env:DEBUG = "true" - Silence stderr:
some-cmd 2>/dev/nullsome-cmd 2>$null
FAQ
Can it translate complex shell scripts?
No - it targets one-liners and short pipelines. Multi-line scripts, set -e semantics, and process substitution don't have clean equivalents.
Are the translations idiomatic?
The PowerShell output prefers cmdlets over aliases (Get-ChildItem over ls) for clarity. You can rewrite back to aliases for interactive use.
What about PowerShell 5.1 vs 7?
Output targets PS 7+ where possible, since 5.1 lacks operators like &&, ||, and ternary ?:. Notes flag the differences when relevant.
Why does my one-liner not translate?
If it uses Bash-isms like process substitution <(...), eval, or heredocs with variable expansion, there's often no clean PowerShell equivalent - those need manual rewrites.