22

I've written a simple bash script for deleting some temporary files that match a certain pattern:

#!/bin/bash
cd ~/some_project/some_dir
rm */*.xml

I've saved it as 'script', chmodded it to +x via 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).

I'm looking for a simple way to keep the terminal from closing until a keypress happens.. is there such a way?

2 Answers 2

22

Add read command to the end of your script. It will wait for a complete line of input (that is, Enter key).

Sign up to request clarification or add additional context in comments.

Comments

10
read -rn1

See help read for more information.

2 Comments

I like the solution to the body character minimum message, lol
-r: If this option is given, backslash does not act as an escape character. -n: read returns after reading nchars characters rather than waiting for a complete line of input. 1: the nchars.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.