{"record":{"id":"fdfaf9004fedb25a","repo":"can1357/oh-my-pi","slug":"bash-requires-a-posix-bash-but-none-was-found","errorCode":null,"errorMessage":"%%bash requires a POSIX bash, but none was found. Install Git for Windows or add a non-WSL bash to PATH.","messagePattern":"%%bash requires a POSIX bash, but none was found\\. Install Git for Windows or add a non-WSL bash to PATH\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/eval/py/runner.py","lineNumber":765,"sourceCode":"    # separate Linux environment and does not share the Windows filesystem\n    # layout or PATH.\n    for env_var, suffix in (\n        (\"ProgramFiles\", r\"Git\\bin\\bash.exe\"),\n        (\"ProgramFiles(x86)\", r\"Git\\bin\\bash.exe\"),\n        (\"LOCALAPPDATA\", r\"Programs\\Git\\bin\\bash.exe\"),\n    ):\n        root = os.environ.get(env_var)\n        if root:\n            candidate = os.path.join(root, suffix)\n            if os.path.isfile(candidate):\n                return candidate\n    found = shutil.which(\"bash\")\n    if found and \"system32\" not in found.lower():\n        return found\n    # WSL's System32 bash.exe runs in a separate Linux environment, so\n    # silently falling back to it would execute the cell somewhere the user\n    # did not intend; fail loudly instead.\n    raise RuntimeError(\n        \"%%bash requires a POSIX bash, but none was found. \"\n        \"Install Git for Windows or add a non-WSL bash to PATH.\"\n    )\n\n\n@cell_magic(\"bash\")\ndef _magic_cell_bash(args: str, body: str) -> int:\n    return _run_shell_body(body, shell_arg=_resolve_bash())\n\n\n@cell_magic(\"capture\")\ndef _magic_cell_capture(args: str, body: str) -> str:\n    \"\"\"Capture stdout/stderr of body; bind to ``args`` (a name) if provided.\"\"\"\n    captured = io.StringIO()\n    saved_stdout, saved_stderr = sys.stdout, sys.stderr\n    sys.stdout = sys.stderr = captured\n    try:\n        _exec_source(body, _STATE.user_ns)","sourceCodeStart":747,"sourceCodeEnd":783,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/eval/py/runner.py#L747-L783","documentation":"The %%bash cell magic locates a POSIX bash via shutil.which('bash') and rejects WSL's System32 bash.exe, which would execute the cell in a separate Linux environment the user did not intend. On Windows when no non-WSL bash is on PATH (or only system32/bash.exe is found), it raises RuntimeError instructing the user to install Git for Windows or add a non-WSL bash.","triggerScenarios":"Executing a %%bash cell on Windows with bash absent from PATH, or where the only 'bash' on PATH is C:\\Windows\\System32\\bash.exe (WSL launcher). The system32 check is case-insensitive on the resolved path.","commonSituations":"Fresh Windows machines without Git for Windows, Git installed but not on PATH, or MSYS2/Cygwin bash installed but PATH not updated. Also CI Windows runners lacking a POSIX shell.","solutions":["Install Git for Windows (its usr/bin/bash.exe is POSIX) and ensure it is on PATH","Add a non-WSL bash directory (e.g. C:\\Program Files\\Git\\bin) to PATH ahead of System32","Verify with `where bash` that the resolved bash is not under System32","On non-Windows platforms ensure bash is installed and on PATH"],"exampleFix":"// before (PowerShell)\n# PATH: C:\\Windows\\System32 only -> %%bash fails\n// after (PowerShell)\n$env:PATH = \"C:\\Program Files\\Git\\bin;$env:PATH\"","handlingStrategy":"fallback","validationCode":"import shutil\nfound = shutil.which(\"bash\")\nbash_ok = bool(found) and \"system32\" not in found.lower()","typeGuard":null,"tryCatchPattern":"try:\n    %%bash\n    echo hello\nexcept RuntimeError as e:\n    if \"requires a POSIX bash\" in str(e):\n        # use an alternative shell cell or report install instructions\n        print(\"Install Git for Windows or add non-WSL bash to PATH\")","preventionTips":["On Windows, install Git for Windows and keep its bin dir on PATH","Never rely on System32 bash.exe (WSL) for %%bash cells","Verify `where bash` output in CI before running %%bash cells"],"tags":["python","windows","bash","environment"],"backgroundTag":"missing-shell-binary","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}