mac笔记本androidstudio使用java函数无法获取环境变量的解决方法
简书链接:mac笔记本androidstudio使用java函数无法获取环境变量的解决方法
文章字数:563,阅读全文大约需要2分钟
1 | println "signfile:"+System.getenv("PS1") |
发现无论是系统的还是 用户目录下的环境变量~/.bash_profile
的都获取为null,下面
https://blog.csdn.net/zhzdeng/article/details/64921967
curl https://raw.githubusercontent.com/ersiner/osx-env-sync/master/osx-env-sync-now -o ~/bin/osx-env-sync-now
如果~/bin
目录不存在,则mkdir
创建一个便是,或者使用系统的bin文件夹也行。
给脚本权限chmod +x ~/bin/osx-env-sync-now
1
在需要重新加载脚本的时候执行命令
1 | 那么改成这样吧 |
aaadeMBP:bin aaa$ curl https://raw.githubusercontent.com/ersiner/osx-env-sync/master/osx-env-sync-now -o /usr/local/bin/osx-env-sync-now
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 283 100 283 0 0 185 0 0:00:01 0:00:01 –:–:– 185
aaadeMBP:bin aaa$ osx-env-sync-now
-bash: /usr/local/bin/osx-env-sync-now: Permission denied
aaadeMBP:bin aaa$ chmod +o osx-env-sync-now
chmod: osx-env-sync-now: No such file or directory
aaadeMBP:bin aaa$ chmod +o /usr/local/bin/osx-env-sync-now
aaadeMBP:bin aaa$ osx-env-sync-now
-bash: /usr/local/bin/osx-env-sync-now: Permission denied
aaadeMBP:bin aaa$ chmod 777 /usr/local/bin/osx-env-sync-now
aaadeMBP:bin aaa$ osx-env-sync-now
/Users/aaa/Library/LaunchAgents/osx-env-sync.plist: No such file or directory
/Users/aaa/Library/LaunchAgents/osx-env-sync.plist: No such file or directory
Environment variables reloaded. Now relaunch your GUI apps to make them aware.
For command line apps, launch a new Terminal session.
aaadeMBP:bin aaa$
1 |
|
curl https://raw.githubusercontent.com/ersiner/osx-env-sync/master/osx-env-sync-now -o /usr/local/bin/qssq-env-sync
1 | 然后```chmod /usr/local/bin/qssq-env-sync``` |
signfile=/Users/aaa/Documents/qssq.keysotre
qssqsignfile=/Users/aaa/Documents/qssq.keysotre
launchctl setenv signfile $signfile
launchctl setenv signfile $qssqsignfile
1 |
|
#!/bin/bash
qssq-env-sync
echo 环境变量已经设置完成
2018-05-13 09:40:40
手痒百度了一下添加自启动。

我的方法是给批处理脚本可执行权限,然后添加这个批处理自启动,这样不需要每次电脑开机启动就要手动执行一次命令了。