title: Sourcetree: A .sh script launched by Sourcetree dosen't know environment variables from ~/.bash_profile
body: <p>Sourcetree allows us to launch a .sh script, which is called Custom action. I am going to register a .sh file to open file with Sublime text. Before doing it, I did a test and found something is weird. the owner of Sourcetree launcher is hello and the owner of Bash shell is also hello like:</p>
  
  <pre><code>choegyutaes-MacBook-Pro:MacOS hello$ pwd
  /Applications/SourceTree.app/Contents/MacOS
  choegyutaes-MacBook-Pro:MacOS hello$ ls -al
  total 6752
  drwxr-xr-x@  3 hello  admin      102 Feb  4  2015 .
  drwxr-xr-x@ 10 hello  admin      340 Aug  9 00:46 ..
  -rwxr-xr-x@  1 hello  admin  3456064 Feb  4  2015 SourceTree
  </code></pre>
  
  <p>But Sourcetree script launcher does not have the exported PATH from ~/.bash_profile.</p>
  
  <pre><code>choegyutaes-MacBook-Pro:scripts hello$ cat ~/.bash_profile
  #MAVEN
  export M2_HOME=/usr/bin/apache-maven-3.3.3
  export M2=$M2_HOME/bin
  export PATH=$M2:$PATH
  #Mysql
  export MYSQL=/usr/local/mysql/bin
  export PATH=$MYSQL:$PATH
  #bash history timestamp
  export HISTTIMEFORMAT="%d/%m/%y %T "
  #Sublime text
  export SUBLIME=/Applications/Sublime\ Text.app/Contents/SharedSupport/bin
  export PATH=$SUBLIME:$PATH
  </code></pre>
  
  <p>my shell script (sublime.sh)</p>
  
  <pre><code>#!/bin/bash
  whoami
  echo $PATH
  sleep 3
  </code></pre>
  
  <p>lanuch script from Bash shell (iTerm)</p>
  
  <pre><code>choegyutaes-MacBook-Pro:scripts hello$ ./sublime.sh
  hello
  /Applications/Sublime Text.app/Contents/SharedSupport/bin:/usr/local/mysql/bin:/usr/bin/apache-maven-3.3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
  </code></pre>
  
  <p>launch script from Sourcetree.
  <a href="https://i.stack.imgur.com/OZDux.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OZDux.png" alt="그림1"></a></p>
  
  <p>as yon can see, the result of echo $PATH is different, but the result of whoami is the same. I think this would not a problem with Sourcetree. It occurs from my unfamiliarance with *nix system and environment variable. Why does not Sourcetree script launcher know the path to Sublime text?</p>