1

According to the bash manual,only login shell will load the /etc/profile file.

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists.

I did not explicitly load the /etc/profile file.

I am wondering why I am using an interactive non-login shell, but can still access the environment variables defined in the /etc/profile file?

# current shell PID
[root@kafka100 cpp]# echo $$
1829

# indicates non-login shell
[root@kafka100 cpp]# shopt | grep login
login_shell     off

# JAVA_HOME was defined in /etc/profile
[root@kafka100 cpp]# echo $JAVA_HOME
/usr/local/src/jdk1.8.0_333

The following is the process tree:

[root@kafka100 cpp]# ps xjf
  PPID    PID   PGID    SID TTY       TPGID STAT   UID   TIME COMMAND
     1   1017   1017   1017 ?            -1 Ss       0   0:00 /usr/sbin/sshd -D
  1017   1109   1109   1109 ?            -1 Ss       0   0:00  \_ sshd: root@notty
  1109   1535   1535   1535 ?            -1 Ss       0   0:00      \_ bash
  1535   1582   1535   1535 ?            -1 S        0   0:00          \_ sh /root/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/bin/code-server --start-server --host=127.0.0.1 --accept-server-license-terms --enable-remote-auto-shutdown --port=0 --telemetry-level all --connection-token-file /root/.vscode-server/.30d9c6cd9483b2cc586687151bcbcd635f373630.token
  1582   1594   1535   1535 ?            -1 Rl       0   0:03          |   \_ /root/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/node /root/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/out/server-main.js --start-server --host=127.0.0.1 --accept-server-license-terms --enable-remote-auto-shutdown --port=0 --telemetry-level all --connection-token-file /root/.vscode-server/.30d9c6cd9483b2cc586687151bcbcd635f373630.token
  1594   1644   1535   1535 ?            -1 Sl       0   0:03          |       \_ /root/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/node /root/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/out/bootstrap-fork --type=ptyHost
  1644   1829   1829   1829 pts/1      2407 Ss       0   0:00          |       |   \_ /usr/bin/bash
[root@kafka100 cpp]# cat /proc/1644/environ | tr '\0' '\n'
XDG_SESSION_ID=1
SELINUX_ROLE_REQUESTED=
SHELL=/bin/bash
SSH_CLIENT=192.168.44.1 51182 22
SELINUX_USE_CURRENT_RANGE=
USER=root
VSCODE_AGENT_FOLDER=/root/.vscode-server
MAIL=/var/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
PWD=/root
LANG=en_US.UTF-8
SELINUX_LEVEL_REQUESTED=
SHLVL=3
HOME=/root
LOGNAME=root
SSH_CONNECTION=192.168.44.1 51182 192.168.44.100 22
LESSOPEN=||/usr/bin/lesspipe.sh %s
XDG_RUNTIME_DIR=/run/user/0
_=/root/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/node
VSCODE_HANDLES_SIGPIPE=true
VSCODE_PARENT_PID=1594
VSCODE_LAST_PTY_ID=0
VSCODE_AMD_ENTRYPOINT=vs/platform/terminal/node/ptyHostMain
VSCODE_PIPE_LOGGING=true
VSCODE_VERBOSE_LOGGING=true
VSCODE_RECONNECT_GRACE_TIME=10800000
VSCODE_RECONNECT_SHORT_GRACE_TIME=300000
VSCODE_RECONNECT_SCROLLBACK=100
NODE_CHANNEL_FD=3
NODE_CHANNEL_SERIALIZATION_MODE=json
[root@kafka100 cpp]# cat /proc/1829/environ | tr '\0' '\n'
XDG_SESSION_ID=1
SHELL=/bin/bash
SSH_CLIENT=192.168.44.1 51182 22
USER=root
MAIL=/var/spool/mail/root
PATH=/root/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/src/jdk1.8.0_333/bin:/usr/local/src/kafka_2.12-3.3.1/bin:/usr/local/src/cmake-3.23.0-linux-x86_64/bin:/root/bin
PWD=/root/workspace/cpp
LANG=en_US.UTF-8
SHLVL=4
HOME=/root
LOGNAME=root
SSH_CONNECTION=192.168.44.1 51182 192.168.44.100 22
LESSOPEN=||/usr/bin/lesspipe.sh %s
XDG_RUNTIME_DIR=/run/user/0
_=/root/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/node
KAFKA_HOME=/usr/local/src/kafka_2.12-3.3.1
HOSTNAME=kafka100
HISTSIZE=1000
CMAKE_HOME=/usr/local/src/cmake-3.23.0-linux-x86_64
JAVA_HOME=/usr/local/src/jdk1.8.0_333
HISTCONTROL=ignoredups
BROWSER=/root/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/bin/helpers/browser.sh
TERM_PROGRAM=vscode
TERM_PROGRAM_VERSION=1.68.1
COLORTERM=truecolor
VSCODE_IPC_HOOK_CLI=/run/user/0/vscode-ipc-5aa8f760-55f0-41a9-9077-f078504d0176.sock
TERM=xterm-256color
3
  • Well, how did you start the shell?
    – ilkkachu
    Commented Feb 23 at 18:29
  • @ilkkachu,I use the VsCode plugin, Remote-SSH
    – hhx
    Commented Feb 23 at 19:07
  • The environment variable could be set in other files than /etc/profile, or that file could be sourced from somewhere else. What is the output of echo $0? Commented Feb 26 at 9:44

0

You must log in to answer this question.

Browse other questions tagged .