title: Difference between /bin/bash and /bin/sh and calling the script directly
body: <p>This is the content of my script</p>
  
  <pre><code>#!/bin/bash
  # test.sh
  # Note: Set permissions on this script to 555 or 755,
  # then call it with ./test.sh or sh ./test.sh.
  echo
  echo "This line appears ONCE in the script, yet it keeps echoing."
  echo "The PID of this instance of the script is still $$."
  # Demonstrates that a subshell is not forked off.
  echo "==================== Hit Ctl-C to exit ===================="
  sleep 1
  exec $0 # Spawns another instance of this same script
  #+ that replaces the previous one.
  echo "This line will never echo!" # Why not?
  exit 99 # Will not exit here!
  # Exit code will not be 99!
  </code></pre>
  
  <p>And this is the output when I run the script using /bin/bash </p>
  
  <pre><code>[user@localhost ~]$ /bin/bash test.sh 
  
  This line appears ONCE in the script, yet it keeps echoing.
  The PID of this instance of the script is still 4872.
  ==================== Hit Ctl-C to exit ====================
  test.sh: line 11: exec: test.sh: not found
  </code></pre>
  
  <p>This is the output when I run the script using /bin/sh</p>
  
  <pre><code>[user@localhost ~]$ /bin/sh ./test.sh 
  
  This line appears ONCE in the script, yet it keeps echoing.
  The PID of this instance of the script is still 4934.
  ==================== Hit Ctl-C to exit ====================
  
  This line appears ONCE in the script, yet it keeps echoing.
  The PID of this instance of the script is still 4934.
  
  ==================== Hit Ctl-C to exit ====================
  </code></pre>
  
  <p>I had to use Ctl-C to stop this.</p>
  
  <p>Why does the same script behave differently based on different mode of execution. FYI: I had to use Ctl-C which I executed the script like this: <code>./test.sh</code></p>