Linux Blog

How to End or Exit a Shell Script

Filed under: Shell Script Sundays — at 9:32 pm on Sunday, January 20, 2008

This week I apologize for the late entry to this column and for the crappy title. But this blog is as much for me to learn as it is for others so this week I’m going to post something that I couldn’t remember how to do correctly. Ending a shell script. Yes, laugh all you want folks, I forgot how to get out of a shell script loop without pressing CTRL+C. I tried the following in the if statement:


The last one I tried was obviously the correct one which is exit. I’m hoping that this happens to every one and not just me. I seem to do it all the time, I just can’t remember the commands for certain things. There are a couple in PHP that I can never remember.

Random Man Pages:


Comment by Cinzia

September 21, 2009 @ 10:49 am

Have u ever tried whit return or exit?
Return goes back to the command line, exit exits the shell.

Comment by

September 22, 2009 @ 8:21 am

@CINZIA Nope, but they would work too. I couldn’t believe I typed in end, die, quit before figuring out that it was exit.

Comment by acarter

January 11, 2011 @ 1:54 pm

You should not feel bad because most of scripts do not use the “exit” command. But today, I needed to use and had to google the answer. Thanks for sharing!

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>