Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote a bash script that logs keycodes in a simple file. I have put the code in a while loop because I want it to log continuosly. But if I run the bash script in the terminal, the cursor just keeps blinking suggesting that the file is indeed caught in an infinte loop. Now i want to be able to quit this loop gracefully. I don't know how. Ctrl+C won't work. I just close the terminal and force quit the process. How do i break out of the while loop as and when the user feels like quitting the program?

share|improve this question
up vote 3 down vote accepted

If you get a blinking cursor you are probably not actually in a loop. You are probably expecting input. Try Ctrl+D. If that doesn't work then open a new terminal and ps aux | grep command where command is the name of the script you wrote and then kill the pid that is returned.

share|improve this answer
The cursor stops blinking after some time, so i know there is a loop going on. I want this script to run on startup. I want to stop the bash script by passing a flag like bash -stop and if i want it to start again it should be something like bash -start How do i go about this? – Vivek Pradhan Jan 22 '13 at 7:43 is a good start, but I can not answer your question directly. You need to find a way to stop all your processing smoothly and use that in the stop hook. – coteyr Jan 22 '13 at 14:13

Just an idea. What if you read value from a file, and instead an infinite loop, you test the value? Something like this:

while [ "`cat mytestfile`" = 0 ]; do
    //your stuff here

And you just echo 1 > mytestfile, if you want to stop the loop.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.