这可能是预期的行为.手册页显示了start-stop-daemon的–env选项:
-e|--env env-name
Set an environment variable whose name and value is env-name
before starting executable. Example: -e HOME="/home/user"
exports an environment variable whose name is HOME with value
"/home/user". Note,only one --env option is suppoted,use
/usr/bin/env if you need more.
作者在示例中使用了$HOME,我认为它通常不会设置它.我没有看到任何其他选项来更新您正在启动的流程的环境.
尝试像这样运行start-stop-daemon:
USER=guest HOME=~guest start-stop-daemon --start --exec /path/to/prog ...
另一种方法是在sudo下运行脚本:
start-stop-daemon --start --exec /usr/bin/sudo -- -H -u guest /path/to/prog
sudo会自动设置$USER,-H选项也会告诉它设置$HOME.我使用自己的test.sh运行这两个,打印变量的值,并根据需要更新它们.我偏爱第一个因为它没有添加另一个程序,但这只是我.