bash - cygwin bash 脚本没有获取参数

标签 bash cygwin

我将 .sh 文件与 bash 相关联。因此我可以从 Windows 命令提示符中成功执行 bash 脚本。

问题是我无法从 Winodws 命令行将命令行参数传递给我的 bash 脚本。

如果我首先进入 bash 然后执行脚本,则命令行参数可以很好地处理。

如果 myscr.sh 是

echo Args $1, $2

然后

c:\> myscr.sh a1 a2
Args ,

但来自 bash:

$ ./myscr.sh a1 a2
Args a1, a2

有什么建议吗?

最佳答案

事实证明这是一个关联问题。

C:\> assoc .sh
.sh=sh_auto_file

C:\> ftype sh_auto_file
sh_auto_file="C:\cygwin\bin\bash.exe" "%1"

那是错误的。它没有将参数传递给 bash。要修复它,只需将 %* 添加到 ftype

C:\> ftype sh_auto_file="C:\cygwin\bin\bash.exe" %1 %*

所有参数都将被传递。

关于bash - cygwin bash 脚本没有获取参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9715612/

相关文章:

bash - 从标准输入解码多个 base64 字符串

bash - 将 Bash 脚本中的命令选项与字符串分开

bash - 将文件追加到不带cat的bash文件中

Android Crypto++ 命令行编译,GNUmakefile

c - Windows 10 上的多线程性能比 Linux 差得多

bash - Git 为单独文件夹中的每个分支获取工作树 - Bash

bash - 为什么 shell 会忽略通过变量传递给它的参数中的引号字符?

command-line - 如何从命令行查找文本文件中的唯一行?

bash - 尝试在 cygwin 中运行脚本时出错

python - Cygwin 看到一个 windows 看不到的文件——我想从 python 访问这个文件