繁体   English   中英

Sourcetree:Sourcetree启动的.sh脚本不知道〜/ .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

从Sourcetree启动脚本。 그림1

正如你所看到的,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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM