我正在尝试source
从launch agent
. 我知道单个变量很容易setenv
,但是我需要引入一堆变量,所以source
这就是我所需要的。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>my.sourcerer</string>
<key>ProgramArguments</key>
<array>
<string>source</string>
<string>my_file.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/path/to/source</string>
</dict>
</plist>
这似乎没有任何问题加载和启动:
$ launchctl load ~/Library/LaunchAgents/my.sourcerer.plist
$ launchctl start ~/Library/LaunchAgents/my.sourcerer.plist
但是当我printenv
没有出现我的源环境变量时。如果手动我这样做:
$ source /path/to/source/my_file.sh
$ printenv
然后所有的变量都出现了。为什么launchctl
代理似乎没有将变量加载到我的环境中?