{"slug": "omni-ps1-is-a-single-file-that-a-dozen-shells-and-scripting-languages-all-accept", "title": "omni.ps1 is a single file that a dozen shells and scripting languages all accept", "summary": "A developer working with Claude created omni.ps1, a single polyglot file that bash, zsh, fish, tcsh, PowerShell 7, Windows PowerShell 5.1, Python 3, Perl 5, Ruby, dash, busybox ash, ksh93 and mksh each execute as their own script, with each interpreter skipping every section except its own and printing one line such as \"lang=bash version=5.3.20(1)-release argc=2 args=alpha beta gamma\". The file routes interpreters through a four-line cascade of header lines that switch each language into a hidden state (comment, string or jump), separating line-at-a-time interpreters like the sh family and tcsh from whole-file parsers like PowerShell, fish, Python, Perl and Ruby that reject any invalid byte. The author calls it \"a toy\" and an experiment in abusing parsers, with no compatibility guarantees and no validation in production, and a CI workflow tests each interpreter across Linux, macOS and Windows.", "body_md": "I believe I have, working with Claude, discovered a way to write one file that bash, zsh, fish, PowerShell, Python and a handful of other interpreters all run as their own.\n\nWarning\n\nWell, seriously. **This is a toy.** It is an experiment in abusing parsers. It has not been validated in any production environment, carries no compatibility guarantees, and should not be used as a template for real scripts.\n\n`omni.ps1` is a single file that a dozen shells and scripting languages all accept. Each interpreter skips every section except its own, and that section prints one line:\n\n``` bash\n$ bash omni.ps1 alpha \"beta gamma\"\nlang=bash version=5.3.20(1)-release argc=2 args=alpha beta gamma\n\n$ fish omni.ps1 alpha \"beta gamma\"\nlang=fish version=4.9.3 argc=2 args=alpha beta gamma\n\n$ pwsh -File omni.ps1 alpha \"beta gamma\"\nlang=powershell version=7.7.0 argc=2 args=alpha beta gamma\n\n$ python3 omni.ps1 alpha \"beta gamma\"\nlang=python version=3.14.10 argc=2 args=alpha beta gamma\n```\n\nThe last three columns list where the CI workflow runs each case.\n\n| Interpreter | Command | Linux | macOS | Windows | \n|---|---|---|---|---|\n| bash | `bash omni.ps1` | yes | yes (bash 3.2) | Git Bash, MSYS2 | \n| sh | `sh omni.ps1` | yes (dash) | yes (bash) | Git Bash, MSYS2 | \n| shebang | `./omni.ps1` | yes | yes | - | \n| dash | `dash omni.ps1` | yes | yes | MSYS2 | \n| busybox ash | `busybox sh omni.ps1` | yes | - | - | \n| zsh | `zsh omni.ps1` | yes | yes | MSYS2 | \n| ksh93 | `ksh omni.ps1` | yes | yes | - | \n| mksh | `mksh omni.ps1` | yes | - | - | \n| tcsh | `tcsh omni.ps1` | yes | yes | MSYS2 | \n| fish | `fish omni.ps1` | yes | yes | MSYS2 | \n| PowerShell 7 | `pwsh -File omni.ps1` | yes | yes | yes | \n| Windows PowerShell 5.1 | `powershell -ExecutionPolicy Bypass -File omni.ps1` | - | - | yes | \n| Python 3 | `python3 omni.ps1` | yes | yes | native, MSYS2 | \n| Perl 5 | `perl -x omni.ps1` | yes | yes | yes | \n| Ruby | `ruby omni.ps1` | yes | yes | yes | \n\nThe sh family picks a sub-branch at run time: zsh, ksh (ksh93 and mksh), bash, or plain POSIX sh (dash, busybox ash). What `sh` and `./omni.ps1` report depends on what `/bin/sh` is on the machine.\n\nInterpreters fall into two groups:\n\n- **Line-at-a-time** (the sh family, tcsh) read and run one command at a time. Only the lines before their own`exit` have to be valid for them.\n- **Whole-file parsers** (PowerShell, fish, Python, Perl, Ruby) reject the file if any byte is invalid, even code they would never run. Every other section must therefore sit inside one of their comments or strings.\n\nThe routing lines at the top form a cascade. Each line switches one language into a \"hidden\" state (inside a comment, a string, or a jump), and later lines no longer need to be valid for that language. Only the first routing line has to be valid everywhere.\n\n| Routing line | Python | PowerShell | fish | sh family and tcsh | \n|---|---|---|---|---|\n| `\"\"\"true\" ,\"\" -eq 1` | `\"\"\"` opens a triple-quoted string that runs until`#\"\"\"` | `\"\"` inside a string is an escaped quote, so this is the string`\"true` ;`,\"\"` builds an array;`-eq` on an array filters it, the result is empty and nothing is printed | `\"\"` followed by`\"true\"` is the command`true` | same as fish | \n| `echo --% >/dev/null;true ' \\| Out-Null <#'` | inside the string | `--%` turns everything up to`\\|` into literal text, which goes to`Out-Null` ; then`<#` opens a block comment | `echo` into /dev/null, then`true` with a one-line quoted argument | same as fish | \n| `true '\\'` | inside the string | inside the comment | `\\'` is an escape inside single quotes, so the string stays open across lines | `\\` is literal inside single quotes, so the string closes | \n| `(exit $?0) \\|\\| goto CSH` | inside the string | inside the comment | inside the string | sh expands `$?0` to`$?` followed by`0` , i.e.`00` : success,`goto` is skipped. tcsh expands`$?0` to`1` (the input file name is known): failure, it jumps to`CSH:` | \n\nAfter the routing lines, each section reopens the hiding construct of every other whole-file parser that has to skip it, and closes its own:\n\n| Language | Hides other sections with | Opener | Closer | \n|---|---|---|---|\n| PowerShell | block comment | `<#` | `#>` | \n| fish | multi-line single-quoted string | `true '\\'` ,`true '` | `#'` | \n| Python | triple-quoted string | `\"\"\"` | `#\"\"\"` | \n| tcsh | `goto` | `goto CSH` | label `CSH:` | \n| Ruby | when the `#!` line does not mention ruby, Ruby skips ahead to the first`#!` line that does | `#!ruby` | `__END__` | \n| Perl | `-x` skips ahead to the first`#!` line that mentions perl | `#!perl` | `__END__` | \n\nClosers start with `#`, so a language that is executing code at that point sees them as ordinary comments.\n\nA section must not contain the closer of any language that is hiding it:\n\n| Section | Must not contain | \n|---|---|\n| sh family, tcsh | `'` ,`\"\"\"` ,`#>` ,`\\` | \n| PowerShell | `'` ,`\"\"\"` ,`\\` | \n| fish | `\"\"\"` ,`#>` ,`\\` | \n| Perl, Ruby | `'` ,`\"\"\"` ,`#>` ;`\\` only as an escape Python accepts, such as`\\n` | \n| Python | `'` ,`#>` | \n\n- `'` ends fish's hiding string, after which fish parses the rest as fish code.\n- `#>` ends PowerShell's block comment.\n- `\"\"\"` ends Python's hiding string.\n- A backslash that is not a valid Python escape makes Python 3.12+ print a `SyntaxWarning` . The script still runs, but the tests treat any stderr output as a failure.\n\n- **LF line endings and no BOM.** CRLF breaks every sh-family shell, and a BOM breaks the shebang.`.gitattributes` forces LF on checkout. Keep the file ASCII-only as well, because Windows PowerShell 5.1 reads files without a BOM in the legacy ANSI code page.\n- **Perl needs `-x`.** Without it, Perl sees`#!/bin/sh` , which does not mention perl, and re-runs the file with`/bin/sh` , so you get the sh branch.\n- **The `.ps1` extension is required by PowerShell on Windows** for`-File` . The other interpreters ignore the extension.\n- **Linters that parse the whole file as sh** (`sh -n` ,`dash -n` , ShellCheck) report errors in the bash-only and non-sh sections. This is expected.\n- **Not supported:** cmd.exe (Windows picks the batch interpreter by the`.bat` /`.cmd` extension, which conflicts with`.ps1` , and cmd would execute every line including`#!` ); JavaScript runtimes (the first routing line is a syntax error there). Classic csh is untested; the tcsh section reads`$tcsh` , which only tcsh defines.\n\nThe test runner needs only Python 3.8+:\n\n```\npython3 tests/run_tests.py              # every installed interpreter; missing ones are skipped\npython3 tests/run_tests.py bash fish    # only these cases; a missing interpreter is a failure\n```\n\nThe runner calls `omni.ps1` with the arguments `alpha` and `beta gamma`. Each case must exit with status 0, write nothing to stderr, and print exactly one line of the form `lang=<name> version=<version> argc=2 args=alpha beta gamma`. The runner also checks that each case reached the expected branch.\n\n`.github/workflows/ci.yml` runs the suite on `ubuntu-latest`, `macos-latest` and `windows-latest`:\n\n- **Linux** installs busybox, fish, ksh, mksh, tcsh and zsh from apt.\n- **macOS** uses the shells that ship with the system, plus fish from Homebrew.\n- **Windows** runs three steps: native pwsh, Windows PowerShell, Python, Perl and Ruby; Git Bash; and an MSYS2 environment for bash, dash, zsh, tcsh, fish and Python.", "url": "https://wpnews.pro/news/omni-ps1-is-a-single-file-that-a-dozen-shells-and-scripting-languages-all-accept", "canonical_source": "https://github.com/SpriteOvO/omni-polyglot", "published_at": "2026-11-29 13:48:10+00:00", "updated_at": "2026-11-29 14:14:47.755179+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["Claude", "bash", "zsh", "fish", "PowerShell", "Python", "Perl", "Ruby"], "also_reported_by": [], "takeaway": "A single file can serve a dozen interpreters by ordering a routing cascade so each line hides the file from one more language, keeping whole-file parsers like PowerShell, fish, Python, Perl and Ruby inside comments or strings while line-at-a-time shells only need the lines before their own exit to b", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/omni-ps1-is-a-single-file-that-a-dozen-shells-and-scripting-languages-all-accept", "markdown": "https://wpnews.pro/news/omni-ps1-is-a-single-file-that-a-dozen-shells-and-scripting-languages-all-accept.md", "text": "https://wpnews.pro/news/omni-ps1-is-a-single-file-that-a-dozen-shells-and-scripting-languages-all-accept.txt", "jsonld": "https://wpnews.pro/news/omni-ps1-is-a-single-file-that-a-dozen-shells-and-scripting-languages-all-accept.jsonld"}}