You are on page 1of 2

Main point about bash

BASH Files
 /etc/profile : It is a system-wide initialization file which is executed when using login shells.
 /etc/bash.bashrc : It is system-wide BASH startup file. Runs when we start BASH for the the
first time in our system after turning it on.
 /etc/bash.logout : It is system-wide BASH cleanup file. Runs at the time of closing BASH for
cleaning the processes of BASH.
 ~/.bash_profile : It is user-based BASH initialization file.
 ~/.bashrc : It is a pre-interactive shell startup file that runs every time we run BASH.
 ~/.bash_logout : It is cleanup file for every shell we have opened.

BASH Startup Scripts and their execution order


Login Shells

Login shells are those, which gets started when we login into a system. Login shells are used to setup
an environment for our system. When environment setup is complete, the control is passed to Non-
Login shell.

A login shell perform the following on startup,

1. On starting, a login shell calls /etc/profile, which runs first every time we login to our system.
2. On succesful execution, the following files are called, *~/.bash_profile, ~/.bash_login &
~/.profile whose roles are described above.
3. The file ~/.bash_profile on running calls ~/.bashrc which in turn further calls /etc/bashrc.
Each of them perform different level of initialization as explained.

Non-Login Shells

Non-Login shells are those, which are started after we have completed the login procedure for a
system.

As the environment for the system is setup by the Login shell itself, so the non-login shell perform the
following on startup,

1. It calls ~/.bashrc which calls /etc/bash.bashrc which in turn calls /etc/profile.d


The functionality for all the files is proveded above in the section mentioning different
BASH files.

BASH Logout Script

When Login Shell exits, BASH exectes the file ~/.bash_logout that logs out the user and calls the
/etc/bash.logout for further clearing the whole system.

 Debugging a BASH Script

To debug a shell script, we can use the command

bash -x SCRIPT

Now, both the input as well as output will be visible.

To debug a shell script every time we run it, we can also modify the shebang line and suppy the
debugging option there only. The modified shebang is,

#!/bin/bash -x

We can also specify the debugging mode after the shebang line using,

#!/bin/bash
set -x

 Converting BASH Scripts to Binary

BASH Scripts can be converted to binaries to hide the functionality of the shell script and prevent users
from accessing it to change or modify its source code.

For conversion of a BASH Script to binary, gcc & shc must be installed on our device.

shc : shc is a command line utility and is a BASH compiler. It is used for the functionality of hiding the
source code & to remove the dependencies to the file by merging them all into a single file.

To convert the BASH script to binary,

shc -f FILE

You might also like