将以下代码放入名为 like 的文件/etc/profile.d/*.sh
中是实现目标的一种可怕方式,但它甚至可能有效:
#/bin/sh
if [ "`id -u`" -eq "`id -u www-data`" ]; then
PATH="/opt/fop/latest:$PATH" ;
fi
我们测试当前用户 id 是否是www-data
-user 的 id。PATH
如果是这样,我们在变量前面加上/opt/fop/latest
目录。每当初始化一个新的 shell 时,它应该自动运行。
这些命令将安装新脚本:
$ echo -e '#!/bin/sh\nif [ "`id -u`" -eq "`id -u www-data`" ]; then PATH="/opt/fpb/latest:$PATH"; fi' | sudo cat >/etc/profile.d/fop4www-data.sh
$ sudo chown www-data:www-data /etc/profile.d/fop4www-data.sh
$ sudo -u www-data chmod +x /etc/profile.d/fop4www-data.sh
如果命令
$ echo 'whoami; echo PATH=$PATH' | sudo -u www-data sh
从正常的 shell 运行反映了变化,你应该能够fop
从你的 php 脚本中调用。
免责声明:我不喜欢 shell 编程。我几乎不知道我在做什么。请使用常识并改进代码。