Environment-Variables
在 /etc/environment 中聲明的 PATH env var 未繼承?
工作
Ubuntu 16.04.05
。根據官方debian和ubuntu文件,其中聲明的變數應該被所有使用者繼承;
那麼下面是如何解釋的:
root@pkara-pc01:~# cat /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" root@pkara-pc01:~# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
(即
/etc/environment
沒有結束的路徑),因為似乎root
PATH
沒有顯式覆蓋:PATH
一種)
/root/.profile
root@pkara-pc01:~# grep -i path /root/.profile root@pkara-pc01:~#
b)
/root/.bashrc
root@pkara-pc01:~# grep -i path /root/.bashrc root@pkara-pc01:~#
C)
/etc/profile
root@pkara-pc01:~# grep -i path /etc/profile root@pkara-pc01:~#
d)
/etc/profile.d/
只有一個PATH
擴展來解釋/snap/bin
root@pkara-pc01:~# grep -rniI -A 1 path /etc/profile.d/ /etc/profile.d/apps-bin-path.sh:3:# Expand $PATH to include the directory where snappy applications go. /etc/profile.d/apps-bin-path.sh:4:if [ "${PATH#*/snap/bin}" = "${PATH}" ]; then /etc/profile.d/apps-bin-path.sh:5: export PATH=$PATH:/snap/bin /etc/profile.d/apps-bin-path.sh-6-fi
更新:
關於@Kusalandra 指出的與此問題的關係,
$ su - Password: root@pkara-pc01:~# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin root@pkara-pc01:~# exit logout /home/pkara/Workspace/gitlab/sonar-scanner $ sudo -i root@pkara-pc01:~# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin root@pkara-pc01:~#
然而:
root@pkara-pc01:~# grep -i secure_path /etc/sudoers Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
所以看起來這兩種情況都
secure_path
適用?(這不是相關問題所說的)。su``sudo
預設路徑來自
/etc/login.defs
,其中包含(至少在 Debian 中,我懷疑它在 Ubuntu 中是相同的):# # *REQUIRED* The default PATH settings, for superuser and normal users. # # (they are minimal, add the rest in the shell startup files) ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ENV_PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
這在您連結到的 Debian wiki 頁面底部提到,在
su
.