Windows Path Contract
Niubash uses a real Windows directory tree for its Unix-shaped shell paths. This is path spelling support, not MSYS, WSL, Cygwin, a POSIX runtime, or a filesystem overlay.
Ownership
| Layer | Responsibility |
|---|---|
| Niubash | Select one winuxcmd.exe, derive its installation root, create the real tree, and configure the shell session. |
| Rubash | Interpret /, /bin, /usr/bin, /etc, /tmp, cd, source, glob, redirects, tests, and command lookup. |
| WinuxCmd | Implement external commands and native Windows filesystem, process, handle, and device operations. |
| WPM | Install package payloads and command links inside the selected installation root. |
Installation Root
For an installed executable such as:
C:/Users/Administrator/AppData/Local/Programs/Niubash/winuxcmd/usr/bin/winuxcmd.exe
the shell root is:
C:/Users/Administrator/AppData/Local/Programs/Niubash/winuxcmd/
usr/bin/
bin/
usr/local/bin/
etc/
var/
dev/
.wpm/
These are ordinary Windows directories. usr/bin is canonical for
winuxcmd.exe, wpm.exe, command links, and filename-only WPM targets.
Explicit WPM targets under bin, usr/bin, or usr/local/bin remain in that
exact directory. .wpm is private package state and is never a command path.
Niubash passes this exact root to Rubash as NIU_ROOT. It is both the
session's root (Rubash records it as __RUBASH_SHELL_ROOT) and a real
process-environment variable, because the bundled WinuxCmd applets resolve the
shell-tree spellings through their own shell_ns::root and therefore read the
child environment (unixwin/niubash#746). Rubash maps paths lexically below it:
/ -> <root>
/usr/bin/tool -> <root>/usr/bin/tool
/bin/tool -> <root>/bin/tool
/etc/config -> <root>/etc/config
/tmp is deliberately NOT part of this tree: it is a per-user temporary
namespace resolved to the real Windows temp directory (TMPDIR, else
%TEMP%), so it stays writable under any install location
(unixwin/niubash#94). /var/tmp resolves beside it as
<real temp>/var/tmp. For every child that is not a bundled WinuxCmd applet,
external command arguments are translated by the Rubash executor with the same
rules — including /mnt/X drive spellings — so there is
exactly one path-semantics owner and no host-side AST rewrite. Device spellings
are not part of that set either, and they split by spelling and child class
(see Special Paths): the exact /dev/null token is rewritten for native
children only, while the fd-bound spellings (/dev/stdin, /dev/fd/N) reach
every child verbatim. One child class is exempt from the drive-form rewrite,
described under Shell Namespace Ownership.
Command lookup and native child PATH use these real directories directly.
Rubash does not merge a second provider directory, and WinuxCmd applets read no
Niubash configuration — only the root published as NIU_ROOT (see Shell
Namespace Ownership). Existing flat installations remain usable when
their directory is explicitly present on PATH; new installs use the tree
above.
Shell Namespace Ownership
A child process either resolves the shell namespace itself or receives native paths — never both, and never a guess about the child's capabilities:
-
Bundled WinuxCmd applets own the shell tree (unixwin/niubash#346). The applets selected by the dispatcher route, the configured root, and the
winuxcmd.exetree marker receive/,/usr/bin,/etc,/tmp,/home,/mnt/X, the bare/, and/dev/*VERBATIM, and resolve them through WinuxCmd's own shell-tree layer, which mirrors Rubash's root map. They therefore render the POSIX face (ls -d /usr/bin,realpath /etc,readlink -f /tmp) and stay consistent with the spelling-preservingpwd. The executable-leaf convention is theirs too:/usr/bin/seqresolves to the realseq.exewhilels -dkeeps the operand spelling, sohead -1 /usr/bin/seqandtest -f /usr/bin/seqagree (niubash#177). -
Every other child — a native Windows program, or a foreign POSIX runtime such as MSYS2 or Cygwin — receives native Windows paths. There is no per-child capability probe and no
MSYS_NO_PATHCONV-style switch; a foreign runtime is treated exactly like a native program. -
The bare
/is the one operand that second class does not receive translated (unixwin/niubash#153, niubash#748)./usr/bin,/etc,/tmp, and/mnt/Xare unambiguously path-shaped, so Rubash translates them for native children; a lone/is also a data operand —expr 10 / 3,tr / X,grep / file— and only the child's grammar can tell the two apart. Rubash therefore hands the bare/over verbatim, and a native child resolves it by its own semantics (on Win32, the current drive's root). Bundled applets still receive it verbatim and map it through WinuxCmd's shell tree, and the grammar mask keeps the data positions ofexpr,tr,grep,sed,awk,find,basename, anddirnameverbatim. Consequence:ls.exe /(applet) is the shell root, whileeza /(a native program) is the current drive root. That is the boundary, not a bug; niubash#748 records the decision to keep it rather than add aNO_CONV-style switch. -
Drive-root forms —
/dand/d/— are handed verbatim to native children too (niubash#779). With-components forms such as/d/repotranslate unconditionally, but the bare root form is also a switch spelling in native grammars:/cis both the C-drive root andcmd.exe's run-and-exit switch, andxcopy /Dandrobocopy /Ehave the same collision. No boundary rule can tell the two apart — an existence test cannot help, because a drive root always exists — so the root forms stay as typed and the child resolves them by its own (Win32, drive-relative) semantics. That is the boundary, not a bug; niubash#779 records the experiment corpus behind the decision, and it applies to every drive uniformly (a former drive-C exception, which also mistranslated data such astr '/c/' X, was removed by the same ruling). To name a drive root for a native program, spell it/d/.,/mnt/d/, orD:/— all three reach the drive root today. -
One exception, and it is not a capability probe:
cmd.exe. A single-letter drive form such as/d/repoor/c/Usersreachescmd.exeverbatim, because/dand/care indistinguishable fromcmd's own switches. Root forms and/mnt/Xspellings are still translated, socmd /c echo /usr/binandcmd /c echo /mnt/c/Usersarrive native whilecmd /c echo /d/repodoes not. The exemption is pinned in Rubash (is_windows_command_processor, and thewindows_cmd_switches_are_not_mapped_into_shell_roottest) and applies tocmd.exealone: a native program that is notcmdreceives/d/repoasD:\repo. -
The MSYS escape spelling
//xis not folded anywhere,cmdincluded (niubash#993 §2).//is MSYS2's own quoting convention: its runtime rewrites a leading//xinto/xprecisely because its own argument conversion would otherwise mangle/xinto a drive path. niu has no such conversion to escape, so a doubled slash reaches the child as typed.cmd //c "echo hi"therefore hands cmd.exe the literal word//c, which cmd does not recognise as a switch, and cmd opens an interactive session — the failure mode is a prompt waiting on stdin (a hang in a script, a stray prompt in a terminal), not an error message and not a nonzero exit. The correct spelling is the one MSYS made fragile:cmd /c "echo hi"works as written, because the cmd.exe exemption above already keeps/cverbatim. A targeted//x→/xfold for single-letter switches of command processors (the gash PR #11 approach) remains an open option; nothing is folded today. -
Namespace bridges stand outside the translation boundary entirely:
wsland the OpenSSH client family (ssh,scp,sftp). Their arguments are not paths on this machine at all — they are interpreted inside another filesystem namespace (a WSL guest's tree, an SSH remote's tree) — so the Rubash executor hands every argument to them byte-for-byte verbatim: no root map, no home/temp map, no drive-form rewrite, no/dev/nullrewrite. Membership in the class is the platform property of being a namespace bridge; the set is the platform's fixed bridges, pinned in Rubash (is_namespace_bridge_programand thepathmatrix_bridge_*tests). A bridge's remote words therefore survive exactly as typed:ssh host cat /var/log/xandwsl cat /home/user/filename the remote/guest files the user spelled, never local ones. -
The bridge's verbatim rule reaches its local-path operands too, so Windows OpenSSH needs native spellings for them (niubash#993 §9).
ssh/scp/sftp/ssh-keygenresolve to the Windows OpenSSH port, which has no MSYS virtual filesystem:ssh -i /c/Users/x/.ssh/key,ssh -F /c/…, the local side of anscp/sftptransfer,ssh-keygen -f /c/…, andIdentityFile/Includelines inside~/.ssh/configmust spell local files in theC:/…(orC:\…) form. A/c/…operand arrives verbatim and fails asWarning: Identity file /c/… not accessible— Git Bash survives the same spelling only because its ssh is an MSYS build that resolves/c/in-process. Remote-path operands are unaffected: inscp local.txt host:/tmp/the remote half still spells the remote tree POSIX-style, which is the namespace that word lives in. (A separate upstream face of the same client family is tracked at PowerShell/Win32-OpenSSH#2478, thessh -tpty branch.) -
Environment variable values follow the same boundary (niubash#1001, rubash#4154). When the shell spawns a child of the second class (a native Windows program, or a foreign POSIX runtime), an exported value that is a path-dialect spelling —
/d/repo, or a colon-separated list of such spellings — is folded to native form (D:\repo; list entries join with;), exactly like an argv operand. Every other value — URLs, relative spellings, non-path data — reaches the child byte-for-byte, and the contract-verbatim variables (PWD,OLDPWD,PATH,TMPDIR,__RUBASH_*) are never folded. A user who needs a path-shaped value delivered verbatim names the variable in__RUBASH_ENV_CONV_EXCL: a;-separated list of variable-name prefixes (*exempts every variable; a trailing=means the exact name). The MSYS2 conversion variable names (MSYS2_ENV_CONV_EXCL,MSYS2_ARG_CONV_EXCL,MSYS_NO_PATHCONV) are not honored: niu has no MSYS conversion layer for a variable to switch off.
The boundary is structural rather than a rename of the "MSYS NO CONV" problem: the shell never asks a child what it can understand. The shipped toolchain's own resolution decides, and the engine compensates only for the child classes that cannot resolve the tree.
User-space trade-off
A user who prefers a native tool (for example eza) over a bundled applet
accepts native path semantics for it, including the lone-/ rule above.
The shell does not rewrite argv to make that tool look POSIX, and no
environment variable turns such a rewrite on. If you want only the common
single-operand ls / spelling to show the shell root, opt in in
~/.niubashrc with a user-owned wrapper (remove any existing alias ls=…
first: an alias wins over a function of the same name):
# ~/.niubashrc — user-space opt-in, NOT part of the shell contract.
# eza is a native Win32 program: a lone "/" is the current drive root.
# This makes only `ls /` (one operand) resolve to the shell root.
ls() {
if [ "$#" -eq 1 ] && [ "$1" = "/" ]; then
command eza -- "$NIU_ROOT"
else
command eza -- "$@"
fi
}
The wrapper is deliberately narrow: eza / called directly, multi-operand
forms such as ls / /usr, and every other native program keep the native
meaning. For POSIX spelling everywhere, use the bundled applets (ls,
find, realpath, …) rather than a native replacement. If your rc already
contains an alias ls=eza line (for example from the setup wizard's
optional eza recommendation, which only appears when you have eza on
PATH), remove that alias before defining the function; niu never rewrites
your rc.
Dispatcher Selection
WINUXCMD_PATH selects one exact dispatcher executable for the session.
Niubash resolves it, prepends that installation's usr/local/bin, usr/bin,
and bin directories to the native PATH, and passes the exact executable to
Rubash. Rubash does not discover another dispatcher from PATH.
The dispatcher is only a fallback when a command is absent from the real tree.
It must not implement Rubash builtins such as cd, export, set, read,
jobs, or trap.
Launcher Precedence (PATHEXT before POSIX)
When a directory on PATH holds both spellings of a tool — the POSIX
launcher bin/tool and the Windows launcher bin/tool.bat / bin/tool.cmd
(the standard pair SDKMAN candidates, Gradle, and Maven ship) — a bare name
resolves to the .bat / .cmd launcher, not the POSIX script
(niubash#993 §12). command -v gradle reports the .bat path; type -a
lists both spellings. Git Bash resolves the same pair to the POSIX script,
so the two shells run different launcher code for the same tool: different
JAVA_HOME probing and GRADLE_OPTS/JAVA_OPTS quoting through cmd.exe,
and a different JAVA_HOME string for the same JDK when the launcher derives
it (the .bat reports the C:/… form, the POSIX script the /c/… form).
The .bat wins deliberately: it needs no $0/dirname resolution, so the
$0-of-PATH-resolved-scripts failure class cannot reach the launcher — that
is why Gradle and Maven work here at all. The installation selection is
unaffected (both shells pick the same SDKMAN candidate or install dir); only
the launcher spelling differs.
Special Paths
~ is USERPROFILE, the same directory used by PowerShell. Windows paths
such as C:/work/file and /c/work/file remain host paths.
The only device spelling currently supported is /dev/null. As a redirect
target it is mapped to the native NUL endpoint. As an external-command
argument it depends on the child class (Shell Namespace Ownership above):
the bundled WinuxCmd applets receive it verbatim — /dev spellings are
shell-namespace arguments their own layer resolves — and the namespace
bridges receive it verbatim, since their words name files in another
namespace; a native child instead receives nul, because the POSIX
spelling names no Windows file it could open. The rewrite covers the
exact token, the value position of name=/dev/null, and the attached
short-option form -o/dev/null (rubash#1506). The other /dev entries
reach every child verbatim; they do not become ordinary files until
their fd or terminal capability is implemented.