在 Windows 批处理文件中运行 bash 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19003799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:03:08  来源:igfitidea点击:

Run bash command in a windows batch file

bashshellbatch-filecmdsh

提问by jb_alvarado

Is it possible to run a msysbash command in a batch script? Let say I have a.batfile in that I have my windows batch commands and in one line I will switch to msysbash to process msysspecified commands. Like so:

是否可以在批处理脚本中运行msysbash 命令?假设我有一个.bat文件,因为我有我的 Windows 批处理命令,并且在一行中我将切换到msysbash 来处理msys指定的命令。像这样:

[...] 
batch commands 
[...]
C:\mingw\msys.0\bin\sh -l
mount 'C:\mingw\local32' /local32
[...] 
bash commands 
[...]

Thanks for help!

感谢帮助!

jb_

jb_

回答by Costi Ciudatu

Why don't you just put all your shell commands in a separate file and just invoke that script from within the batch file in one line ?

为什么不将所有 shell 命令放在一个单独的文件中,然后从批处理文件中的一行中调用该脚本?

C:\mingw\msys.0\bin\sh your-msys-script.sh

回答by jb_alvarado

I found now a better way: I use the mintty console, it works with other I think also. The mintty is under msys/1.0/bin, with a shortcut I point to mintty with the parameter: /bin/sh -l. Now I can send from a batch file parameter to that shortcut. For example: mintty.lnk script.sh

我现在找到了一个更好的方法:我使用 mintty 控制台,它也适用于我认为的其他控制台。mintty 位于 msys/1.0/bin 下,我使用快捷方式指向 mintty,参数为:/bin/sh -l。现在我可以从批处理文件参数发送到该快捷方式。例如:mintty.lnk script.sh