现有方案的问题:
/etc/environment
和~/.config/environment.d/
仅接受NAME=VAL
格式- 全部放在
/etc/profile
不美观且不支持分用户
解决方案:
- 使用
/etc/profile.d/usr_env.sh
加载对应用户的的~/.local/profile.d/*.sh
具体实施:
创建并编辑
/etc/profile.d/usr_env.sh
1#!/bin/sh 2profileDir="/home/${USER}/.local/profile.d" 3if test -d ${profileDir}; then 4 for profile in ${profileDir}/*.sh; do 5 test -r "$profile" && . "$profile" 6 done 7 unset profile 8fi 9unset profileDir
创建
~/.local/profile.d
文件夹并创建编辑*.sh
注销后重新登录生效