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 have a .sh script that starts a java service of mine (I didn't write this).

Can someone explain how this actually executes?

start() {

   # setup classpath
  . $ROOT/bin/

  RUN="java -Dlog.root=$VAR $JOPTS $CP $MAIN -v"

  # start


When start gets called, it builds sets the variables for the options and class path (java stuff), but when does this line do?


Is $RUN something built in at all?

I want to convert this over to a upstart script, and upstart requires me to use exec like:

        [ "$enabled" = "1" ] || [ "$force_start" = "1" ] || exit 0
        # Setup Serviio specific properties
        JAVA_OPTS=" -Djava.awt.headless=true -Dderby.system.home=$SERVIIO_HOME/library -Dserviio.home=$SERVIIO_HOME -Xmx512M -Xms20M -XX:+UseParNewGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20"
        # construct classpath
        cd $SERVIIO_HOME
        for i in lib/*.jar; do
        # write to syslog - for debugging
        # logger -t $0 -- "starting: /usr/bin/java $JAVA_OPTS -classpath $CLASSPATH org.serviio.MediaServer"
        exec /usr/bin/java $JAVA_OPTS -classpath $CLASSPATH org.serviio.MediaServer
end script
share|improve this question
RUN="java -Dlog.root=$VAR $JOPTS $CP $MAIN -v" creates a bash variable RUN. I think $RUN 2>>$OUT_FILE >>$OUT_FILE & prints the contents of RUN into two files. – Seth Feb 19 '13 at 4:12

As Seth mentioned, $RUN is defined previously in the script with the RUN="java ..." line. The line is executed, and standard output and standard error messages are both appended to the $OUTFILE which presumably is also defined in the script (or specified by commandline parameter).


is bash code for redirecting the stderr stream. By default, stdout and stderr are both output to the tty (your bash prompt) where they are displayed, but you can redirect the output. By default, using >> file will only redirect the standard output (stuff that is printed using echo - this is the usual form of output for most programs. However, when programs wish to put out an error, this will go on the standard error output stream, which (by default) is printed to the terminal, and is NOT redirected using >>. To redirect the error stream as well (perhaps for error logging) you use 2>> file, which will append it to file. Interestingly, the same effect as in the script could be achieved by using &>> $OUTFILE, which is shorthand for "redirect both stdout and stderr".

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.