title: I am puzzled with the differences between "sh xxx.sh" and "./xxx.sh" for running a shell script
body: <p>Here, I have a shell script named <code>load.sh</code>.</p>
  
  <p>It start my program named "demo" with supervise,
  When I run it with <code>sh load.sh start | stop</code>, it works well.</p>
  
  <p>However, when I run it with <code>./load.sh start | stop</code>, it works bad. the demo is frequently started(and exit) by the supervise.</p>
  
  <p>What's the problem of the two ways of running the shell script?
  and is there any problem(bug) in the script cause the supervise frequently restart the demo?
  Thanks a lot!</p>
  
  <pre><code>#!/bin/bash
  
  cd `dirname $0` || exit
  mkdir -p status/demo
  
  dir_name=`pwd`
  STR_LIB=${dir_name}/lib
  
  if [ -z "${LD_LIBRARY_PATH}" ]; then
      export LD_LIBRARY_PATH="${STR_LIB}"
  else
      export LD_LIBRARY_PATH="${STR_LIB}:${LD_LIBRARY_PATH}"
  fi
  
  start() {
              sleep 1
              bin/supervise.demo -u status/demo bin/demo &gt;/dev/null 2&gt;&amp;1 &amp;
  }
  
  stop() {
              if [ -f status/demo/lock ]; then
                  supervise_demo_pid=`/sbin/fuser status/demo/lock`
                  `ps -ef | grep "$supervise_demo_pid" | grep "supervise.demo" | grep -v grep &gt; /dev/null 2&gt;&amp;1`
                  if [ $? -eq 0 ] &amp;&amp; [ "$supervise_demo_pid" != "" ] ; then
                      echo "kill supervise.demo process:"${supervise_demo_pid}
                      kill -9 $supervise_demo_pid
                  fi
              fi
  
              if [ -f status/demo/status ]; then
                  demo_pid=`od -An -j16 -N2 -tu2 status/demo/status`
                  `ps -ef | grep "$demo_pid" | grep "demo" | grep -v grep &gt; /dev/null 2&gt;&amp;1`
                  if [ $? -eq 0 ]; then
                      echo "kill demo process:"${demo_pid}
                      kill -9 $demo_pid
                  fi
              fi
  }
  
  case "$1" in
          start)
              stop
              start
              echo "Done!"
              ;;
          stop)
              stop
              echo "Done!"
              ;;
             *)
             echo "Usage: $0 {start|stop}"
             ;;
  esac
  </code></pre>