简体   繁体   English

通过桌面快捷方式运行bash脚本时保持终端打开

[英]Keeping terminal open when running a bash script from a desktop shortcut

I am running a bash script from my desktop off of a shortcut I made for it. 我正在从桌面上使用为它创建的快捷方式运行bash脚本。 When I click on it it says "Execute in Terminal" which is the option I want to do. 当我单击它时,它说“在终端中执行”是我要执行的选项。 The bash script compiles and runs a java program I made and the point of the script is to handle the errors that the program may through through the compiling prosses to someone who has very little programming experience (not really important to the question though). bash脚本编译并运行一个我编写的Java程序,该脚本的要点是处理该程序可能会通过编译过程给几乎没有编程经验的人(虽然对该问题并不重要)造成的错误。 When I launch it, it will open the terminal as expected. 当我启动它时,它将按预期打开终端。 When it encounters the error it will print out the error to the screen as one would expect it to do but then will immediately close the terminal it opened. 当遇到错误时,它将错误输出到屏幕上,就像人们期望的那样,但是随后将立即关闭它打开的终端。

What I want is for the terminal to stay open until someone exits the terminal so they can read the errors. 我想要的是使终端保持打开状态,直到有人退出终端,以便他们可以读取错误为止。

I suggest you to add a line of code at the end of your bash script with a read operation as follows: 我建议您在bash脚本的末尾添加一行代码,并执行以下读取操作:

read -p 'Hit ENTER to exit'

This will keep the terminal visible until you hit ENTER. 这将使终端可见,直到您按下ENTER键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM