Sourcetree: A .sh script launched by Sourcetree dosen’t know environment variables from ~/.bash_profile

There’s a ability to get launched a .sh script in Sourcetree, 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:

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

But Sourcetree script launcher does not have the exported PATH from ~/.bash_profile.

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

my shell script (sublime.sh)

#!/bin/bash
whoami
echo $PATH
sleep 3

lanuch script from Bash shell (iTerm)

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

launch script from Sourcetree.
그림1

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 familiarance with *nix system and environment variable. Why does not Sourcetree script launcher know the path to Sublime text?


Source: shell

Leave a Reply