/etc/profile

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search

/etc/profile contains Linux system wide environment and startup programs. It is used by all users with bash, ksh, sh shell. Usually used to set PATH variable, user limits, and other settings for user. It only runs for login shell. If you wanted to make large changes or application specific changes use /etc/profile.d directory.

Sample /etc/profile

pathmunge () {
	if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
	   if [ "$2" = "after" ] ; then
	      PATH=$PATH:$1
	   else
	      PATH=$1:$PATH
	   fi
	fi
}
 
# ksh workaround
if [ -z "$EUID" -a -x /usr/bin/id ]; then 
	EUID=`id -u`
	UID=`id -ru`
fi
 
# Path manipulation
if [ "$EUID" = "0" ]; then
	pathmunge /sbin
	pathmunge /usr/sbin
	pathmunge /usr/local/sbin
fi
 
# No core files by default
ulimit -S -c 0 > /dev/null 2>&1
 
if [ -x /usr/bin/id ]; then
	USER="`id -un`"
	LOGNAME=$USER
	MAIL="/var/spool/mail/$USER"
fi
 
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
 
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
    INPUTRC=/etc/inputrc
fi
 
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
 
for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
    	. $i
    fi
done
 
unset i
unset pathmunge
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox
Print/export