0

according to POSIX, the ENV environment variable is used to specify initialization files to be read (such as some kind of .profile and .rc files), but if this variable is used to specify these files, how can we set it?

Normally, one would put an export FOO="..." in their initialization files, but this variable needs to be set before those files are read (it needs to be set so they can be read)

1
  • ENV=/some/path /path/to/shell? And of course some implementation-specific method like pam_environment, systemd's environment.d, etc. Commented Aug 5, 2024 at 4:40

1 Answer 1

1

The point is that you would set it to the path to some file in your ~/.profile (which is your session initialisation file, not a shell customisation file) or any other place to customise your session (like ~/.xsession, or PAM env file as relevant to your system) for it to become a shell customisation file:

  • ~/.profile:

    ENV=~/.shrc export ENV
    # other env var setting
    
  • ~/.shrc:

    # things that need to be redone for every shell and are
    # generally local to the shell
    alias la='ls -A'
    var=value
    

Beware the $ENV was originally sourced by even non-interactive invocation. That's no longer the case for POSIX compliant sh implementations, but could be a problem on systems that still have a Bourne shell or old ksh88.

Now, people generally don't use sh as their interactive shell, and shells like zsh, fish, bash have their own customisation method.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.