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 my own shell script, and I made it executable with chmod +x command. But when I click to shell file and want to run it in terminal, it suddenly opens and then closes in a second. What is the problem?

share|improve this question
When scrpits have errors they exit. So unless you list the contents of the script its a guessing game – Meer Borg Apr 23 '13 at 12:18
no, script hasn't any error. I just want to simply run it in Terminal with clicking to the current file. – Ziyaddin Sadigov Apr 23 '13 at 13:07
Also, it's not true that scripts always exit when they have errors. Scripts such as rc.local, which are run with sh -e, will do (essentially) this. But most scripts don't run that way. Of course many scripts are deliberately written to exit under a variety of specific error conditions, but the author of the script would know about this if they had deliberately written their script that way. – Eliah Kagan Oct 9 '14 at 23:03
up vote 5 down vote accepted

It also closes automatically once it has run your command.
Add /bin/bash at the end of your script to keep the terminal open.

You can also add a && sleep 10 to keep the terminal open 10 seconds and see what's going on.

Alternatively, add another line containing read at the end of the script to keep the terminal open until you press Enter.

share|improve this answer
or add the sleep 10 to the exit point (end?) of the script. – Elder Geek Oct 10 '14 at 2:43

Try commenting out all your "exit" commands (if any) in your script by placing # in front of them and give it a go. Perhaps you are executing "exit" in your shell that closes the terminal session.

share|improve this answer
Welcome to askubuntu! Your answer while possible may be a bit late as the OP already accepted the other answer. Your help is of course appreciated, however you might be better served by focusing your efforts on these: – Elder Geek Oct 10 '14 at 2:46

I have faced a similar situation. I was executing my script as


Instead try executing it as


This worked for me.

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.