如何在Powershell的独立新窗口上用一些参数启动gitbash



我正在尝试从Powershell执行以下步骤。下面只是一个伪代码,它解释了我的需求。

# This is a powershell function  
function load(){  
cd C:my_pathscripts
invoke-expression -Command C:Program FilesGitgit-bash.exe 
# I want to go to this path into the git-bash.exe window
cd C:my_pathscripts 
# I have bash script here. I want to excuete this script.   
./loadData.sh
}

我如何通过Powershell实现这一点?谢谢

尝试git-bash.exe --help,看看它有什么参数。经过短暂的谷歌搜索后,我认为你可以运行Start-Process -FilePath "C:Program FilesGitgit-bash.exe" -ArgumentList '--cd="C:my_pathscripts" --exec="loadData.sh"',甚至Start-Process -FilePath "C:Program FilesGitgit-bash.exe" -ArgumentList '--exec="C:my_pathscriptsloadData.sh"'也可能工作。

如果您只是想执行bash脚本loadData.sh,请运行:

cd C:my_pathscripts
path/to/bash.exe loadData.sh

这将创建一个bash shell(在当前控制台中,而不是在单独的控制台中(,运行脚本,然后退出,返回到powershell。

如果当前工作目录没有在bash shell中按预期设置,那么您可以将其作为参数传递给脚本:

# not 100% tested, I don't have a Powershell at hand
path/to/bash.exe loadData.sh /c/my_path/scripts
# and in your loadData.sh, add an instruction :
cd "$1"

最新更新