title: Bash: Execute script in context of calling shell
body: <p>My understanding is that when I execute a script inside a BASH shell using syntax like <code>$ ./myscript.sh</code> a sub-shell is started and the code runs in that shell, with STDOUT and STDERR output being printed on my shell, STDIN is taken from my shell. This is how script are interactive.</p>
  
  <p>The top line of the file "<em>myscript</em>" is <code>#!/bin/bash</code>, this states the interpreter to be used to execute the syntax within the script file.</p>
  
  <p>If I use the syntax <code>source myscript.sh</code> the code in my script is "pulled" in to my current environment and executed there, rather than in a sub-shell. I can't make the following code run in a script that I call with <code>$ ./myscript.sh</code> and effect my current shell:</p>
  
  <pre><code>#!/bin/bash
  
  PS1='`
    if [ $? -eq 0 ];
      then echo -n "\[\033[00;35m\]\u\[\033[01;32m\]@\[\033[00;35m\]\h\[\033[00;32m\](\[\033[01;35m\]\W\[\033[01;32m\])\[\033[00;32m\]\$";
      else echo -n "\[\033[00;35m\]\u\[\033[01;31m\]@\[\033[00;35m\]\h\[\033[01;31m\](\[\033[35m\]\W\[\033[31m\])\[\033[00;31m\]\$";
    fi`\[\033[0m\]'
  </code></pre>
  
  <p>If I drop the <code>#!/bin/bash</code> and use <code>source</code> this script changes my command prompt. Can it be arranged in a script in such a fashion that I can call it with <code>$ ./myscript.sh</code> and it will make the change to my current shell, not the sub shell?</p>