0

I'd like to put code into a file, which when a new session is made is invoked for all users on a Debian system.

/etc/profile is only touched by login sessions.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
Karl Morrison
  • 1,621
  • 4
  • 29
  • 43
  • @AndrewSchulman You mean this wall of text which I don't understand half of it? https://linux.die.net/man/1/bash – Karl Morrison Mar 08 '18 at 14:54
  • You want to read the chapter on **Invocation** which explains exactly which files get loaded when bash is started, as a interactive (login) shell or not. – HBruijn Mar 08 '18 at 15:02
  • @HBruijn is correct. But I removed my comment referring to `man bash` because reading the Invocation section now, it seems that there's no system-wide file that's executed for non-login sessions. Sorry. – Andrew Schulman Mar 08 '18 at 15:05
  • @AndrewSchulman No worries Andrew :) – Karl Morrison Mar 08 '18 at 15:28

1 Answers1

0

File which is invoked by all users for new bash sessions

When you read the chapter on Invocation in the manual you'll know that there is no such file. https://linux.die.net/man/1/bash

I don't have a Debian box at hand but it might be that Debian does something similar to what RHEL/CentOS do: by default those distro's deploy from /etc/skell both a ~/.bash_profile and a ~/.bashrc to the users home directory.

When bash is invoked as an interactive login shell the ~/.bash_profile should be loaded.

/etc/skel/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc

By loading the ~/.bashrc from ~/.bash_profile you get a file that will be loaded for both normal and login sessions.

/etc/skel/.bashrc

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# User specific aliases and functions  

The ~/.bashrc in turn will load global /etc/bashrc and you get a system wide file that gets loaded for both login as well as non-login interactive bash sessions.

HBruijn
  • 77,029
  • 24
  • 135
  • 201