Shell configuration

From Initq

Jump to: navigation, search

Contents

Files

When you turn your machine on the first thing that gets loaded is the bootloader, then the kernel starts the first process called init. itit always has the process id 1.

[root@initq etc]# ps -eaf | grep init
root         1     0  0 Mar04 ?        00:00:14 init [5]

The init process reads a file called /etc/inittab. inittab runs all the rc scripts for the proper runlevel and then waits for the login. The login scripts all depend of the default shell. First login script that is run is /etc/profile.

/etc/login

An interactive login shell is started after a successful login, using /bin/login, by reading the /etc/passwd file. This shell invocation normally reads /etc/profile and its private equivalent ~/.bash_profile upon startup.

Another file to look at is /etc/login.defs. Under Linux password related utilities and config file(s) comes from shadow password suite. The /etc/login.defs file defines the site-specific configuration for this suite. This file is a readable text file, each line of the file describing one configuration parameter. The lines consist of a configuration name and value, separated by whitespace.

Setting global path

  • ubuntu = /etc/environment
  • debian = /etc/login.defs
  • redhat = /etc/profile
# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /sbin
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
    pathmunge /sbin after
fi

Add, remove, or replace pathmunge entries in the desired order to suit the application's needs. Save the file and then logout and log back in for the new settings to take effect.

/etc/profile

this file contains the environment variables and start up programs. This file is run at login time. this is a system wide initialization file. This file starts by setting up some helper functions and some basic parameters. It specifies some bash history parameters and, for security purposes, disables keeping a permanent history file for the root user. It also sets a default user prompt. It then calls small, single purpose scripts in the /etc/profile.d directory to provide most of the initialization. the /etc/profile also calls the /etc/profile.d directory and all the *.sh files in it. They contain individualized configurations for the system.

/etc/inputrc

If the shell variable "INPUTRC" is set, probably in "/etc/profile" the keybindings are set by the file declared in the INPUTRC value. Usually this is "/etc/inputrc". Otherwise the keybindings are set in the file "$HOME/.inputrc" for each individual user.
   $HOME/.inputrc - User's keybindings definition 
   /etc/inputrc - Global keybindings definition

/etc/profile.d

 [alibaba@ohnonono profile.d]$ ls
 colorls.csh  glib2.sh               krb5-devel.sh         lang.sh   vim.sh
 colorls.sh   gnome-ssh-askpass.csh  krb5-workstation.csh  less.csh  which-2.sh
 cvs.sh       gnome-ssh-askpass.sh   krb5-workstation.sh   less.sh
 glib2.csh    krb5-devel.csh         lang.csh              vim.csh

/etc/bashrc

this file contains shell aliases and functions.

~/.bash_profile

If you want each new user to have this file automatically, just change the output of the command to /etc/skel/.bash_profile and check the permissions after the command is run. You can then copy /etc/skel/.bash_profile to the home directories of already existing users, including root, and set the owner and group appropriately.

~/.bashrc

The comments and instructions for using /etc/skel for .bash_profile above also apply here. Only the target file names are different.
 [alibaba@ohnonono skel]$ pwd
 /etc/skel
 [alibaba@ohnonono skel]$ ls -la
 total 48
 drwxr-xr-x  2 root root  4096 Dec  2 03:21 .
 drwxr-xr-x 95 root root 12288 May 25 04:02 ..
 -rw-r--r--  1 root root    24 Jul 12  2006 .bash_logout
 -rw-r--r--  1 root root   176 Jul 12  2006 .bash_profile
 -rw-r--r--  1 root root   124 Jul 12  2006 .bashrc

~/.bash_logout

 [alibaba@ohnonono skel]$ cat .bash_logout
 # ~/.bash_logout
 clear

Loading sequence

The sequence of files is this : /etc/profile --> /etc/profile.d --> /etc/bashrc --> ~/.bash_profile --> ~/.bashrc --> ~/.bash_logout.

reload .bash_profile

you can do:

$ . .bash_profile
$ source .bash_profile

Prompt

Change the prompt with:

[a507394@localhost ~]$ export PS1=`echo -ne "\u@\h:\w\$ "`
a507394@localhost:~$

-n do not output the trailing newline

-e enable interpretation of backslash escapes

$PS2 has >, it is used for prompting for additional info.

$IFS is the separator, normally a space.

$0 is the name of the shell.

$# number of parameters passed

$$ process id.

$1, $2 .. parameters given to the script.

$* A list of all the parameters separated by $IFS.

$@ all parameters without $IFS.

lexiana@initq:~$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$
lexiana@initq:~$ echo $PS2
>
lexiana@initq:~$ echo $IFS
 
lexiana@initq:~$ echo $0
bash
lexiana@initq:~$ echo $#
0
lexiana@initq:~$ echo $$
17578

No Logout

If you hit CTRL+D you get logged out, to avoid this put the following in your .bash_profile.

  • export IGNOREEOF=2
[a507394@localhost ~]$ Use "logout" to leave the shell.
[a507394@localhost ~]$ Use "logout" to leave the shell.

Timeout for idle users

[a507394@localhost ~]$ export TMOUT=600

The TMOUT is in seconds. Put this in their .bash_profile.

Personal tools