gpt4 book ai didi

windows - 将基于 Windows 斜杠 (/) 的参数从 bash 脚本传递给程序

转载 作者:可可西里 更新时间:2023-11-01 12:15:47 25 4
gpt4 key购买 nike

我正在尝试从我的 bash 脚本运行以下命令。 (bash 通过 msysgit 安装)

taskkill /IM ssh-agent.exe

我在屏幕上从 taskkill 得到的输出是:

ERROR: Invalid argument/option - 'C:/Program Files/Git/IM'.
Type "TASKKILL /?" for usage.

可执行文件正在运行,但是 /IM 正在扩展,无论我试图做什么来逃避它...


我试过使用 \/IM 但它发送 \/IM 时没有转义斜杠,我尝试了几种不同的方法通过 eval 运行它, cmd/c start 等...但它们似乎都有问题。我也尝试过 set -o noglob,但也没有用。 $'\057/'IM 或类似的尝试也没有...

最佳答案

由于我的评论实际上提供了答案,所以我会发布它。

如何将正斜杠转义为另一个正斜杠,如 //。当我执行此命令并转义 /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

关于windows - 将基于 Windows 斜杠 (/) 的参数从 bash 脚本传递给程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34647591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com