如何在 Linux Bash 脚本终止时防止终端窗口关闭?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14446391/
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
How to prevent terminal window from closing when Linux Bash Script terminates?
提问by Click Upvote
I've written a simple bash script for deleting some temporary files that match a certain pattern:
我编写了一个简单的 bash 脚本来删除一些匹配特定模式的临时文件:
#!/bin/bash
cd ~/some_project/some_dir
rm */*.xml
I've saved it as 'script', chmodded it to +xvia terminal. Now when I double click this file, I get the option to Run it in terminal or display its output. If I click Run in terminal, the script correctly works, however the terminal window closes immediately. I'd rather the window stay open so I can see if there were any errors (and possibly get rm to display names of deleted files if possible).
我已将其保存为“脚本”,并+x通过终端将其修改为。现在,当我双击这个文件时,我可以选择在终端中运行它或显示其输出。如果我单击在终端中运行,脚本可以正常工作,但终端窗口会立即关闭。我宁愿窗口保持打开状态,以便我可以查看是否有任何错误(如果可能,可能让 rm 显示已删除文件的名称)。
I'm looking for a simple way to keep the terminal from closing until a keypress happens.. is there such a way?
我正在寻找一种简单的方法来防止终端关闭,直到按键发生.. 有这样的方法吗?
回答by Anton Kovalenko
Add readcommand to the end of your script. It will wait for a complete line of input (that is, Enterkey).
将read命令添加到脚本的末尾。它将等待完整的输入行(即Enter键)。

