0

I added a line echo $PATH > /home/z/path.txt to the front of /etc/profile and found the content of /home/z/path.txt was as follows:

/usr/local/bin:/usr/local/sbin:/usr/bin

Part of the modified /etc/profile:

# /etc/profile

# Set our umask
umask 022
echo $PATH > /home/z/path.txt

# Append "$1" to $PATH when not already in.
# This function API is accessible to scripts in /etc/profile.d
append_path () {
    case ":$PATH:" in
        *:"$1":*)
            ;;
        *)
            PATH="${PATH:+$PATH:}$1"
    esac
}

# Append our default paths
append_path '/usr/bin'
append_path '/usr/local/sbin'
append_path '/usr/local/bin'

As you can see the PATH is not empty when /etc/profile is processed. My question is: before /etc/profile is processed, what script sets the PATH variable?

I've looked through /etc/environment but I don't think it's the one I am looking for:

#
# This file is parsed by pam_env module
#
# Syntax: simple "KEY=VAL" pairs on separate lines
#

QT_AUTO_SCREEN_SCALE_FACTOR=1

QT_QPA_PLATFORMTHEME="gnome"

QT_STYLE_OVERRIDE="kvantum"

# Force to use Xwayland backend
# QT_QPA_PLATFORM=xcb

#Not tested: this should disable window decorations
# QT_WAYLAND_DISABLE_WINDOWDECORATION=1

EDITOR=/usr/bin/nano

I am using zsh shell on manjaro.

z.h.
  • 904
  • 6
  • 25
  • Are you starting your shell in a terminal emulator in a graphical session or in a tty? Possibly related, though the question is about Bash: https://unix.stackexchange.com/q/227989/315749 – fra-san Oct 09 '20 at 16:08
  • If you just do `echo $PATH > /home/z/path.txt`, you're overwriting the file, so how are you guaranteeing that the output you see is not from some invocation that already had `$PATH` in the environment? (Also, even if you do something like `env -u PATH /bin/zsh -c 'declare PATH'`, you'll still see zsh's [built-in default `PATH`](https://github.com/zsh-users/zsh/blob/19390a1ba8dc983b0a1379058e90cd51ce156815/Src/init.c#L980).) And of course, zsh is sourcing `zshenv`, and `/etc/zprofile`, before it gets around to `emulate sh -c 'source /etc/profile'` in `/etc/zprofile` – muru Oct 09 '20 at 16:16
  • @fra-san I tried in tty6 and gnome-terminal. same result. – z.h. Oct 09 '20 at 16:36
  • @fra-san The link you provided is quite helpful. I think the value is set in `/etc/login.defs` after I checked its content. – z.h. Oct 09 '20 at 16:57
  • muru Thanks for the comment. I didn't really know the exact procedure of login so I didn't think too much before putting that line in /etc/profile. – z.h. Oct 09 '20 at 17:00

0 Answers0