将基于 windows 斜杠 (/) 的参数从 bash 脚本传递给程序
Passing windows slash (/) based parameters to a program from bash script
我正尝试从我的 bash 脚本中 运行 以下内容。 (bash 通过 msysgit 安装)
taskkill /IM ssh-agent.exe
我从 taskkill
屏幕上得到的输出是:
ERROR: Invalid argument/option - 'C:/Program Files/Git/IM'.
Type "TASKKILL /?" for usage.
可执行文件是 运行ning,但是 /IM
正在扩展,无论我如何尝试逃避它...
我试过使用 \/IM
但它发送 \/IM
时没有转义斜杠,我尝试了几种不同的方法 运行 通过 eval、cmd / c 开始,等等......但他们似乎都有问题。我也试过 set -o noglob
,但也没用。 $'7/'IM
或类似的尝试也没有...
在寻找 "disable bash file expansion" 等各种搜索后,我通过专门搜索 "bash" "windows" taskkill
我试图 运行 的可执行文件找到了它,我遇到了 ,终于对我有用了。
cmd " /c taskkill /F /IM ssh-agent.exe"
既然我的评论确实提供了答案,我就post吧。
如何将正斜杠转义为另一个正斜杠,如 //
。当我执行此命令并转义 /r
参数时,它对我有用:
start C:/folder/beep 2000 250 100 //r 3
来源:http://oldwiki.mingw.org/index.php/switches%20with%20forward%20slashes
Minimalist GNU for Windows
Passing switches with forward slashes under 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
Use:
cmd //c echo foo
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)
The x var now contains the windows equivalent path to /unix/path
我正尝试从我的 bash 脚本中 运行 以下内容。 (bash 通过 msysgit 安装)
taskkill /IM ssh-agent.exe
我从 taskkill
屏幕上得到的输出是:
ERROR: Invalid argument/option - 'C:/Program Files/Git/IM'.
Type "TASKKILL /?" for usage.
可执行文件是 运行ning,但是 /IM
正在扩展,无论我如何尝试逃避它...
我试过使用 \/IM
但它发送 \/IM
时没有转义斜杠,我尝试了几种不同的方法 运行 通过 eval、cmd / c 开始,等等......但他们似乎都有问题。我也试过 set -o noglob
,但也没用。 $'7/'IM
或类似的尝试也没有...
在寻找 "disable bash file expansion" 等各种搜索后,我通过专门搜索 "bash" "windows" taskkill
我试图 运行 的可执行文件找到了它,我遇到了
cmd " /c taskkill /F /IM ssh-agent.exe"
既然我的评论确实提供了答案,我就post吧。
如何将正斜杠转义为另一个正斜杠,如 //
。当我执行此命令并转义 /r
参数时,它对我有用:
start C:/folder/beep 2000 250 100 //r 3
来源:http://oldwiki.mingw.org/index.php/switches%20with%20forward%20slashes
Minimalist GNU for Windows
Passing switches with forward slashes under 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
Use:
cmd //c echo foo
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)
The x var now contains the windows equivalent path to /unix/path