title: Why does specifying my shell change the EUID of root?
body: <p>If I specify my shell as /bin/bash in a script, then the EUID of root is 0.  If I don't, and the script runs in my default shell (also /bin/bash), the EUID of root is an empty string!  I'm new to scripting and thought there was no difference as long as bash ran the show.</p>
  
  <p>The code I'm running checks if the program is run by root, and restarts the program as sudo if not.</p>
  
  <pre><code>#!/bin/bash
  echo euid = $EUID
  echo shell = $SHELL
  
  if [ $EUID -ne 0 ]; then
      sudo "$0"
      exit $?
  fi
  </code></pre>
  
  <p>When run, I see</p>
  
  <pre><code>euid = 1000
  shell = /bin/bash
  euid = 0
  shell = /bin/bash
  </code></pre>
  
  <p>But if I remove the she-bang line, I get </p>
  
  <pre><code>euid = 1000
  shell = /bin/bash
  euid =
  shell = /bin/bash
  ./test.sh: 4: [: -ne: unexpected operator
  </code></pre>
  
  <p>The script runs in the same shell all four times, so why does it act differently when sudo calls it without specifying /bin/bash?</p>
  
  <p>I'm running Ubuntu 14.04 if that matters.</p>
  
  <p>Thanks in advance!</p>