从bash脚本将基于Windows斜杠(/)的参数传递给程序 [英] Passing windows slash (/) based parameters to a program from bash script
问题描述
我正在尝试从bash脚本运行以下命令. (通过msysgit安装的bash)
I'm trying to run the following from my bash script. (bash installed via msysgit)
taskkill /IM ssh-agent.exe
我在taskkill
屏幕上得到的输出是:
The output I get on the screen from taskkill
is:
ERROR: Invalid argument/option - 'C:/Program Files/Git/IM'.
Type "TASKKILL /?" for usage.
可执行文件正在运行,但是/IM
正在扩展,无论我为逃避它做了什么...
The executible is running, but the /IM
is being expanded regardless of what I try to do to escape it...
我尝试使用\/IM
,但是随后它发送了\/IM
而没有转义斜线,我尝试了几种通过eval,cmd/c start等运行它的方式,但是它们似乎都有问题.我也尝试过set -o noglob
,它也没有用. $'\057/'IM
或类似尝试都没有...
I've tried using \/IM
but then it sends \/IM
without escaping the slash, I've tried a few different ways of running it through eval, cmd /c start, etc... but they all seem to have issues. I've also tried set -o noglob
, which also didn't work. neither did $'\057/'IM
or similar attempts...
推荐答案
由于我的评论确实提供了答案,因此我将其发布.
如何将正斜杠转义为//
之类的另一个正斜杠.当我执行以下命令以转义/r
参数时,它对我有用:
start C:/folder/beep 2000 250 100 //r 3
How about escaping a forward slash to another forward slash like //
. It works for me when I execute this command where I escaped the /r
parameter:
start C:/folder/beep 2000 250 100 //r 3
来源: http://oldwiki.mingw.org/index. php/switchs%20with%20forward%20slashes
Windows的极简GNU
在MSYS下通过带有正斜杠的传递
在MSYS中,命令行参数"/c"被解释为C: 驱动器,因此需要传递任何以正斜杠开头的参数 使用两个正斜杠.例如,要在MSYS中使用此命令:
In MSYS a command line argument of "/c" is interpreted as the C: drive, so to pass any argument beginning with a forward slash you need to use two forward slashes. For example, to use this command in MSYS:
cmd /c echo foo
使用:
cmd //c echo foo
如果您需要外壳脚本中具有路径的Windows样式,则可以 可以做
If you need to have the windows-style of a path in a shell script, you can do
x=$(cd /unix/path && cmd //c cd)
x var现在包含/unix/path的Windows等效路径
The x var now contains the windows equivalent path to /unix/path
这篇关于从bash脚本将基于Windows斜杠(/)的参数传递给程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!