Windows 版 Git 中的 Bash:使用 CMD.exe/C 和 args 运行命令时的怪异 [英] Bash in Git for Windows: Weirdness when running a command with CMD.exe /C with args

查看:22
本文介绍了Windows 版 Git 中的 Bash:使用 CMD.exe/C 和 args 运行命令时的怪异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这更像是一个烦恼而不是一个问题,但我非常想了解这里的语义.

This is more of an annoyance rather than a problem but I would very much like to understand the semantics here.

我想要做的就是在临时命令提示符会话上运行任意命令,该会话本身在 bash 会话下运行.

All I want to do is to run an arbitrary command on a temporary command-prompt session which itself running under a bash session.

我的成功率为 50/50,因为某些命令按预期工作,而其他命令则不然.

My success rate is 50/50 as some command works as expected whereas others not so much.

我认为问题可能在于参数没有正确排列(即缺少或合并的参数)

I think the problem may lie around arguments not lining up properly (i.e. missing or merged arguments)

我将尝试通过一系列命令和响应来解释我所说的奇怪是什么意思.(我试图让 test 字样打印在屏幕上.)

I'll try to explain what I mean by weird by a series of commands and responses. (I'm trying to get the word test to be printed on the screen.)

我在 GNU bash,版本 3.1.0(1)-release (i686-pc-msys) 下运行这些,与 Git-1.8.4 捆绑:

I'm running these under GNU bash, version 3.1.0(1)-release (i686-pc-msys) Bundled with Git-1.8.4:

第一次尝试:

$ cmd /c echo test
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
c:>

第二次尝试:

$ cmd '/c echo test'
test"

第三次尝试:

$ cmd "/c echo test"
test"

第四次尝试:

$ cmd /c echo test
test"

第五次尝试:

$ cmd "/c echo" test
'echo" test' is not recognized as an internal or external command,
operable program or batch file.

我非常感谢对上述行为的任何指示或见解,因为这对我来说是不直观的,让我发疯!

I'd really appreciate any pointers or insights into the behaviors above as this is unintuitional to me and driving me crazy!

另一个问题 看起来与此类似,但实际上并非如此,主要是因为它是关于通过不需要任何参数的 CMD/C 运行批处理文件.

There is another question that appears similar to this, but it really isn't, mainly because it's about running batch files through CMD /C that doesn't require any arguments.

它并没有真正回答我关于如何为 Windows 命令行应用程序正确提供参数的问题,即使示例是关于 CMD/C 的,这里的答案也可以应用于许多其他 Windows 命令行应用程序.

It doesn't really answer my question about how to provide arguments properly to windows command line apps, and even though the examples are about CMD /C, the answer here can be applied to many other Windows command line apps as well.

推荐答案

这实际上记录在 ReleaseNotes 文件中(在您安装的 Git for Windows 的顶级文件夹中)

This is actually documented in the ReleaseNotes file (in the top level folder of your installed Git for Windows)

此外,传递 Windows 程序 Windows 路径时必须格外小心,因为它们对 MSys 风格的 POSIX 路径一无所知——您可以使用类似 $(cmd//c echo "$POSIXPATH") 之类的东西.

Also, extra care has to be paid to pass Windows programs Windows paths, as they have no clue about MSys style POSIX paths -- You can use something like $(cmd //c echo "$POSIXPATH").

如果您使用 cmd//c echo test 它会按预期工作.

If you use cmd //c echo test it works as expected.

$ cmd //c echo test
test

原因是试图确保 posix 路径最终正确传递给 git 实用程序.出于这个原因,Git for Windows 包括一个影响命令参数的修改后的 MSYS 层.您应该注意,不打算将 Git for Windows 提供的 bash shell 和工具用作 Windows 的通用 unix 工具.如果你想要一个通用的 unix 风格的工具集,那么你应该安装 MSYS 或 cygwin.Git Bash shell 是为使用 git 而设置的,有时会显示.

The cause is to do with trying to ensure that posix paths end up being passed to the git utilities properly. For this reason, Git for Windows includes a modified MSYS layer that affects command arguments. You should note that it is not intended that the bash shell and tools provided with Git for Windows be used as general purpose unix tools for Windows. If you want a general purpose unix-style toolset then you should install MSYS or cygwin. The Git Bash shell is setup for working with git and sometimes that shows.

这篇关于Windows 版 Git 中的 Bash:使用 CMD.exe/C 和 args 运行命令时的怪异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆