Bash in Git for Windows: Weirdness when running a command with CMD.exe /C with args

前端 未结 7 2275
后悔当初
后悔当初 2020-12-05 02:55

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

All I want to do is to run an arbitrary command on a

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 03:00

    I noticed git-bash treats the /c argument like a C: drive:

    C:\Windows\system32\cmd.exe C:/ echo test
    

    As dbenham found double quotes are added. This echos test" for example:

    cmd /c\ echo\ test
    

    I needed the same line (script) to work in git-bash as well as Cygwin Bash. The only ways that work are

    cmd /c\ echo\ test\&rem\ 
    

    (note that this line needs to end in a space), and

    cmd << EOC
    echo test
    EOC
    

    So escape every space after the /c and add \&rem\  at the end of the line (including the trailing space), or just wrap the command in a here document.

    All this probably depends on the version of git-bash and the specific commands. :-(

提交回复
热议问题