我将 .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/