Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Just a minor issue. I'm writing a simple bash script that starts and stops Jetty. When I execute it, the script immediately puts my cursor back on the bash prompt. However, as Jetty starts up and writes its initialization output back to stdout, it leaves the cursor on a line of its own (without a prompt) until I enter a command or hit enter. Nitpicking, I know, but I figure there's an easy way to avoid this that I'm missing.

Here's the script:

cd /opt/jetty/jetty-distribution-7.4.5.v20110725/
if [ "$1" = "-stop" ]
    java -DSTOP.PORT=8079 -DSTOP.KEY=something -jar start.jar --stop
    java -DSTOP.PORT=8079 -DSTOP.KEY=something -jar start.jar &

Here's the output:

[user@machine ~]# jetty
[user@machine ~]# 2011-08-11 14:47:34.818:INFO::jetty-7.4.5.v20110725
2011-08-11 14:47:34.866:INFO::Deployment monitor /opt/jetty/jetty-distribution-7.4.5.v20110725/webapps at interval 1
2011-08-11 14:47:34.878:INFO::Deployment monitor /opt/jetty/jetty-distribution-7.4.5.v20110725/contexts at interval 1
2011-08-11 14:47:34.883:INFO::Deployable added: /opt/jetty/jetty-distribution-7.4.5.v20110725/contexts/javadoc.xml
2011-08-11 14:47:34.934:INFO::started o.e.j.s.h.ContextHandler{/javadoc,file:/opt/jetty/jetty-distribution-7.4.5.v20110725/javadoc}
2011-08-11 14:47:34.935:INFO::Deployable added: /opt/jetty/jetty-distribution-7.4.5.v20110725/contexts/test.xml
2011-08-11 14:47:35.011:INFO::Extract jar:file:/opt/jetty/jetty-distribution-7.4.5.v20110725/webapps/test.war!/ to /tmp/jetty-
2011-08-11 14:47:35.645:INFO::started o.e.j.w.WebAppContext{/,file:/tmp/jetty-},/opt/jetty/jetty-distribution-7.4.5.v20110725/webapps/test.war
2011-08-11 14:47:36.127:INFO:org.eclipse.jetty.servlets.TransparentProxy:TransparentProxy @ /javadoc to
2011-08-11 14:47:36.199:INFO::Started SelectChannelConnector@ STARTING

And the cursor ends up on a blank new line just below. Is there a way to prevent this? I'm pretty new to bash scripting, is there something I should be doing that I'm not?

share|improve this question
up vote 4 down vote accepted

You can't prevent this easily – bash does not receive any signal at all when a background process writes to the terminal, only when it exits completely. (SIGTTOU is only delivered to the writing process, in this case Java, which doesn't have any control over when the prompt is displayed...)

share|improve this answer
Thank you, very informative. If I could upvote you, I would. :) – B. Striegel Aug 11 '11 at 19:56

You could redirect output to a file for the java commands

share|improve this answer
I tried that at first, but changing those lines to, say: java -DSTOP.PORT=8079 -DSTOP.KEY=something -jar start.jar --stop 1> /root/jetty.log 2>&1 has no effect, it just creates a blank jetty.log file and still prints to stdout. – B. Striegel Aug 11 '11 at 19:56

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.