title: Symbols in startup.sh of Apache Tomcat
body: <p>I've been trying to make my own 'Daemon' java thread.<br/><br/></p>
  
  <p>I couldn't quite get what I wanted, so I got curious about how Tomcat stays alive even
  after I disconnect the ssh connection.<br/></p>
  
  <p>So I decided to poke around the Tomcat source files, to see if I could find 'the magic'. <br/>
  In startup.sh there are some weird looking things I tried to find on the Internet without luck.<br/>
  <br/></p>
  
  <p>in startup.sh</p>
  
  <pre><code>    # resolve links - $0 may be a softlink
  PRG="$0"
  
  while [ -h "$PRG" ] ; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-&gt; \(.*\)$'`
    if expr "$link" : '/.*' &gt; /dev/null; then
      PRG="$link"
    else
      PRG=`dirname "$PRG"`/"$link"
    fi
  done
  
  PRGDIR=`dirname "$PRG"`
  EXECUTABLE=catalina.sh
  
  # Check that target executable exists
  if $os400; then
    # -x will Only work on the os400 if the files are: 
    # 1. owned by the user
    # 2. owned by the PRIMARY group of the user
    # this will not work if the user belongs in secondary groups
    eval
  else
    if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
      echo "Cannot find $PRGDIR/$EXECUTABLE"
      echo "The file is absent or does not have execute permission"
      echo "This file is needed to run this program"
      exit 1
    fi
  fi 
  
  exec "$PRGDIR"/"$EXECUTABLE" start "$@"
  </code></pre>
  
  <ol>
  <li>What is '$0' ? </li>
  <li>What's '$@' ?</li>
  </ol>
  
  <p>What do they do ?
  <br/>
  <b>EDIT</b><br/>
  Perhaps this really doesn't have much to do with the OQ but I just wanted to share what I've found.<br/>
  After analysing the source code of Apache Tomcat, I figured it out. I'm not sure if this is 
  how Tomcat actually runs. <br/>
  What I wanted was something like a daemon process.<br/>
  First you need a launcher written in java. From within the Launcher, make a process and exec("java yourDaemonToBe");<br/>
  Hope this helps. </p>