且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Windows命令提示符下运行.sh?

更新时间:2022-11-02 23:10:10

错误讯息表示您尚未安装 bash ,或不在您的 PATH 中。



顶部的Google匹配是 http://win-bash.sourceforge.net/ ,但你还需要理解大多数Bash脚本期望一个类Unix环境;所以只是安装Bash不太可能允许你运行在网络上找到的脚本,除非它是专门为这个特定的使用场景设计的。通常的解决方案是 https://www.cygwin.com/ ,但有很多可能的选择,取决于它是什么



如果Windows不是您的使用场景的核心,安装一个免费操作系统(也许是虚拟化)可能是最简单的方法。



第二个错误消息是由于Windows名义上接受正斜杠作为目录分隔符,但在此上下文中,它被解释为一个开关分隔符。换句话说,Windows将您的命令行解析为 app / build /build.sh (或者用Unix选项约定, app --build --build.sh )。您可以尝试 app\build\build.sh ,但由于上述情况,它不太可能工作。


How can I run .sh on Windows 7 Command Prompt? I always get this error when I try to run this line in it,

app/build/build.sh

error,

'app' is not recognized...

or,

bash app/build/build.sh

error,

'bash' is not recognized...

Any ideas what have I missed?

Here the screen grab,

The error message indicates that you have not installed bash, or it is not in your PATH.

The top Google hit is http://win-bash.sourceforge.net/ but you also need to understand that most Bash scripts expect a Unix-like environment; so just installing Bash is probably unlikely to allow you to run a script you found on the net, unless it was specifically designed for this particular usage scenario. The usual solution to that is https://www.cygwin.com/ but there are many possible alternatives, depending on what exactly it is that you want to accomplish.

If Windows is not central to your usage scenario, installing a free OS (perhaps virtualized) might be the simplest way forward.

The second error message is due to the fact that Windows nominally accepts forward slash as a directory separator, but in this context, it is being interpreted as a switch separator. In other words, Windows parses your command line as app /build /build.sh (or, to paraphrase with Unix option conventions, app --build --build.sh). You could try app\build\build.sh but it is unlikely to work, because of the circumstances outlined above.