PATH set before /etc/zshenv

5

1

I am trying to find which file adds /opt/texbin folder to my PATH variable on Ubuntu. It is not present in my /etc/environment file. sudo grep -lr texbin . 2>/dev/null outputs nothing in the /etc folder. And still if I add set -x to the beginning of my /etc/zshenv file I can see that /opt/texbin is in my PATH before zsh sources this file.

Any ideas?

sencer

Posted 2014-06-23T17:44:50.493

Reputation: 431

Is it in /etc/profile? – BenjiWiebe – 2014-06-23T17:45:09.350

Nope. I checked the file now and it's not in it, neither in any files in profile.d. Also as I said, grepping /etc folder gives nothing :/ – sencer – 2014-06-23T17:47:18.647

1It is possible that it is due to a file in /etc, but not directly entered in the file, for instance if it gets /opt/texbin from the output of some other command and puts it in PATH. – BenjiWiebe – 2014-06-23T17:49:11.703

Makes sense. Couldn't think of a way of testing though -- can you? – sencer – 2014-06-23T17:51:42.367

I think I might be able to find it if I was sitting down at your computer, but I'm not sure.....How about giving me SSH access (with sudo access, of course)? :) – BenjiWiebe – 2014-06-23T17:52:33.003

What OS are you using? What created the /opt/texbin folder? – BenjiWiebe – 2014-06-23T17:53:31.867

Is it in any of the /etc/z* files? – BenjiWiebe – 2014-06-23T18:22:26.670

Sorry for late response. Of course, and would you need my bank accounts also? :) My OS is Ubuntu, and /opt/texbin is actually not existing and this is why I am trying to remove it from PATH. I have no idea how it entered into my PATH but I believe it has something to do with Texlive 2013. It is not in any of /etc/z* files. – sencer – 2014-06-24T17:04:16.950

Answers

4

I would try this approach to track down the source of /opt/texbin in your PATH variable:

  1. To get a list of files, which are actually read in (e.g. a non-standard file might be sourced by another file!), you can invoke zsh with the SOURCE_TRACE option enabled:

    $ zsh -o sourcetrace
    +/etc/zshenv:1> <sourcetrace>
    +/home/user/.zshrc:1> <sourcetrace>
    +/home/user/.zcompdump:1> <sourcetrace>
    +/home/user/.zshrc-last:1> <sourcetrace>
    
  2. Check these files, where the PATH variable come into play:

    $ grep -ie "path.*=" files_from_step_1
    

    The case insensitivity is crucial, since zsh uses the array $path, which automatically gets converted to the bash-like colon-separated list $PATH and vice versa.

  3. If still not lucky, try to include a debug message in /etc/zshenv, where commands are first read from:

    print -l $path
    

    This will give you a nice list of the PATH variable, which zsh inherits from its parent process (display manager, init process, etc.).*

  4. If the path is indeed inherited from the starting process, it is crucial to know which processes are relevant:

    $ pstree -apH $$
    

    This produces a process tree, where the shell process (pid in $$) is highlighted. Check the config files for these processes, too, and keep in mind that

    • source /some/file or . /some file can also alter the PATH
    • if you edit e.g. /etc/profile in your current console, log off and log in again, the parent process (X logon manager) might still have the old environment.+

* As you have written, the PATH already contains /opt/texbin before /etc/zshenv is read, checked by set -x in /etc/zshenv. I get no output with this technique, but with my step 3, hence I included the other steps in my answer as well.

+Suffered myself badly due to this behavior some time ago...

mpy

Posted 2014-06-23T17:44:50.493

Reputation: 20 866

1

The correct way to activate execution trace or source trace at the time /etc/zshenv is loaded is to activate it at the shell command: zsh -l -o xtrace, zsh -l -o sourcetrace -- be sure to try with the -l option, since the path element might only be added at login.

Beside this, if you are still getting a path element added before /etc/zshenv is loaded, you could check for a ~/.pam_environment file. This is the user-local version of the /etc/environment file and is loaded at about the same time, before the shell or user environment. Check the man page "pam_env" for more details about the format used - it is different for the user file.

One other minor possibility is the ENV environment variable. When a SH-compatible shell is started in SH-compatible mode, the file whose path is in ENV is loaded as a startup file before anything else. Search your shell's documentation for more detail. login.defs is also used at login and by various user/login utilities, but /etc/environment is the standard for all modern login systems and is prefered for establishing the PATH variable.

Micah

Posted 2014-06-23T17:44:50.493

Reputation: 13

1

The PATH variable that is passed to your shell at log-in is defined in /etc/login.defs. There are two setups here, ENV_SUPATH and ENV_PATH. Depending if you login as root or as a user, one of the two is passed to the shell via the environment variable PATH. After the PATH variable is passed to the shell, any additional changes are controlled by the shell's start-up scripts.

Friartek

Posted 2014-06-23T17:44:50.493

Reputation: 21