打开git bash shell窗口,执行命令并在条件信号后保留 [英] Open git bash shell window, execute command and remain after term signal

查看:130
本文介绍了打开git bash shell窗口,执行命令并在条件信号后保留的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理文件,它通过打开许多"git bash" shell窗口来设置环境.这项功能与一项令人烦恼的功能完全不同,该功能令人讨厌,在该功能中,如果您按Ctrl C(或发送任何其他术语信号),整个bash窗口将关闭.

I have a batch file that sets up my environment by opening a number of "git bash" shell windows. This works perfectly apart from one annoying feature where if you press Ctrl C (or send any other Term signal) the whole bash window will close.

我希望窗口的行为就像已正常打开一样,因此当它接收到术语信号时,它会返回到bash提示符.

I want the window to behave as if it has been opened normally and so when it receives a term signal it goes back to the bash prompt.

这是我的setup.bat文件的当前内容:

Here is the current contents of my setup.bat file:

C:
cd \project\
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login -i -l -c "source ali.sh && mvn spring-boot:run"
cd \project2\
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login

请注意,第一个启动命令运行maven,当我想重新启动命令(按Ctrl + C)时,它将关闭整个窗口.第二个启动命令在该目录中创建一个新的bash窗口,即使使用Ctrl + C,它也可以像普通bash窗口一样工作,但是我希望它在开始时运行命令.

Note that the first start command runs maven and when i want to restart the command (press Ctrl+C) it closes the whole window. The second start command creates a new bash window in that directory which works like a normal bash window even with Ctrl+C, BUT I want it to have run a command at the start.

这可能吗?非常感谢您的帮助

Is this possible? Many thanks for all your help

推荐答案

类似的方法可能对您有用:

Something like this might work for you:

C:
cd \project\
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login -i -l -c "sh -c 'source ali.sh && mvn spring-boot:run; exec sh'"

诀窍是将命令包装在以下位置:

The trick is wrapping the command in:

sh -c '...; exec sh'

其中 sh 是您的外壳,可能是 bash .

Where sh is your shell, might be bash.

您实际上可能只需要给每个命令加上后缀: exec sh ,例如:

You might actually to able to just suffix each command with: exec sh, eg:

start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login -i -l -c "source ali.sh && mvn spring-boot:run; exec sh"

这篇关于打开git bash shell窗口,执行命令并在条件信号后保留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆