-
Notifications
You must be signed in to change notification settings - Fork 859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bash.exe unusual commandline parsing #1746
Comments
Interestingly, it does seem to match MSYS's bash (I wonder if there's some shared code):
I don't know about things other than bash, but I expect there's an extra layer of escaping for backslashes going on when running from cmd.exe. |
@zrax Your example has a little problem: You echo a string that contains
I get this (correctly, see
|
And regarding calling from bash or from cmd: AFAIK: When calling from msys2's bash, there happens some stuff in the background:
To view the given CommandLine, one can enable the CommandLine column in the details pane in TaskManager. |
Hmm, perhaps my example was a bit convoluted (it was related to something else I was working on). I did try the echo without the sed to be sure I was translating the same string beforehand though, but my examples are piping the whole command through bash (rather than letting cmd.exe handle the arguments). As another side-note, quoting the "a\b" in msys causes it to drop the backslash like WSL's bash, but does not change the output for WSL's bash. EDIT: Just saw your latest update -- that makes more sense for my cases then. |
I saw your answer and assume with However cygwin and msys2 rules are still very close to MS rules, and if arguments are quoted with Its also somewhat strange in cygwin and msys2: When calling from cygwin/msys2 out to a native executable, they follow the common rules, but when calling from outside into cygwin/msys2 they invent their own rules... |
@benhillis as a response to your comment:
I don't know if there is any chance to get this changed, but as I think that this is really important, I just have to list arguments for this. I don't think there are "Linux argument parsing" rules. Any Linux executable gets it's arguments as already split argv-array. Sure, there are POSIX-shell or bash parsing rules. But if you call On Windows this is sadly not true. On Windows, each executable does it's own CommandLine splitting. This leads to some kind of anarchy. It's almost impossible, to programatically call executables, without risking that arguments are interpreted wrong. Luckily almost all modern compilers on Windows generate executables that split arguments using a single set of rules: these rules. Many modern script interpreter follow these rules as well. Therefore it's in most cases possible to programatically call executables by generating a CommandLine with the inverse of these rules. This is for example done by:
All those shells/systems currently can't safely call WSL's Finally, I'll qoute @mklement0 (I hope this is ok for you, @mklement0)
It might not really be possible, but we should definitely try to get as close as possible. But if Microsoft decides, to officially release a new executable, that massively disrespects any common CommandLine splitting rules, that is a step in the exact opposite direction. (I think it's not to late to change this, as WSL is still beta.) |
I think, even for Linux users, the current behavior is unexpected: If, on linux, I start shell If we apply this to the current case, a linux user should expect, that he needs to quote |
I just noticed, that even though the default behavior of
Adding a parameter to wsl.exe to call the default shell with the commandline arguments parsed as in any other normal exe (an alias for If you wan't to argue about the "way that one expects", then yes the current behavior might not be that strongly unexpected for users of cmd, but for anybody who calls wsl from anywhere else (MSYS bash/powershell/one of the shells mentioned above) then the current behavior is disastrous - see for example this issue at the powershell repo. If Keeping the behavior as it is currently, discourages wsl users from using any shell other than cmd.exe - which is certainly not what Microsoft had in mind, as AFAIK cmd is deprecated. |
If I understand it correctly,
bash.exe
is a Windows commandline-executable, that starts WSL's/bin/bash
and forwards given arguments.As on linux (and WSL) executables are started with an argument array, but on windows executables are started with a single CommandLine,
bash.exe
needs to split the given CommandLine into multiple arguments, that can be redirected to/bin/bash
.As
bash.exe
is a Windows executable, in my opinion it should split the CommandLine into multiple arguments using usual Windows rules.However the rules that are used to convert the CommandLine into multiple arguments are quite different. Its very confusing, if almost all executables use these rules, but then Microsoft publishes a new executable that conflicts with those rules.
Expected results:
bash.exe
should split the commandline like thisActual results (with terminal output if applicable):
bash.exe
uses strange own rules to split commandline, only partly compatible to usual rules.At least the second of those examples fails,
a\\b
should staya\\b
and not becomea\b
:In cmd:
outputs:
( I use
-c "xargs -0 printf '%s\n' < /proc/$$/cmdline"
to print arguments, because to use something with$@
or similar, I would have to pass double quotes to bash, and as mentioned, I don't know howbash.exe
parses those...)Windows build number:
Version 10.0.14393 Build 14393
The text was updated successfully, but these errors were encountered: