Linux sysadmin question (since it's no longer possible to find actual answers via search on the Internet):

How can I configure the PATH to *always* have a specific directory in it when a shell (Bash) is started, regardless of whether the shell is login/non-login, interactive/non-interactive, etc.?

The normal steps (adding a file in /etc/profile.d which adds to the path) work for login/interactive shells, but not for shells opened by sshd with a command to execute (no pty).

#Linux #SysAdmin #LinuxSysAdmin

@kevin This is for Bash specifically. Each shell works a bit differently.

For login shells (interactive or not), it runs `/etc/profile`, then `~/.bash_profile`, `~/.bash_login`, and `~/.profile`.

For interactive non-login shells, it runs `~/.bashrc`.

For non-interactive non-login shells, you have to set `BASH_ENV` to a script to run before you run Bash. You need to give the full path of the script, I think.

If you are running a script or command over sshd (rather than logging in and interacting with commands as usual), it'll run `~/.bashrc`.

Here's the doc page: https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

Bash Startup Files (Bash Reference Manual)

Bash Startup Files (Bash Reference Manual)

@bryanredeagle Sadly the default ~/.bashrc (at least on Debian) exits immediately if the shell is non-interactive, so that doesn't help much and of course it isn't global. Thanks though 🙂

@kevin Then Debian is probably doing something before it gets to your `.bashrc`.I think maybe in `/etc/bash.bashrc` (but that might just be Ubuntu...).

If you're willing to switch to Zsh, they have the `.zshenv` file. It is always ran in every shell, and is ran first.