[英]Can we load environment variables from ~/.bash_profile without having to source ~./bash_profile?
[英]Sourcetree: A .sh script launched by Sourcetree dosen't know environment variables from ~/.bash_profile
Sourcetree允許我們啟動.sh腳本,稱為自定義操作。 我將注冊一個.sh文件以使用Sublime文本打開文件。 在做之前,我做了一個測試,發現有些奇怪。 Sourcetree啟動器的所有者是您好,Bash shell的所有者也是:
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
但是Sourcetree腳本啟動器沒有從〜/ .bash_profile導出的PATH。
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
我的shell腳本(sublime.sh)
#!/bin/bash
whoami
echo $PATH
sleep 3
來自Bash Shell(iTerm)的lanuch腳本
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
正如你所看到的,echo $ PATH的結果是不同的,但是whoami的結果是相同的。 我認為Sourcetree不會有問題。 它是由於我對* nix系統和環境變量不熟悉而發生的。 為什么Sourcetree腳本啟動器不知道Sublime文本的路徑?
.bash_profile僅用於在終端中運行bash shell。
您可能正在通過快捷方式或菜單運行SourceTree。
如果從bash提示符運行SourceTree,則應該發現它采用了.bash_profile設置和導出的環境。
假設就是這樣,那么您需要使快捷方式或菜單具有相同的快捷方式(我不知道OS-X),但是必須有一些方法可以為整個用戶上下文設置環境(即,對於在Windows 2000下啟動的任何進程)用戶會話,菜單中的圖形或bash shell或其他內容。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.