top of page

Shell Scripting:


what is shell:

A shell is special user program which provide an interface to user to use operating system services. Shell accept human readable commands from user and convert them into something which kernel can understand. It is a command language interpreter that execute commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or start the terminal.

what is kernel:

The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system.

It manages following resources of the Linux system –

  • File management

  • Process management

  • I/O management

  • Memory management

  • Device management etc.

There are several shells are available for Linux systems like –

  • BASH (Bourne Again SHell) – It is most widely used shell in Linux systems. It is used as default login shell in Linux systems and in macOS. It can also be installed on Windows OS.

  • CSH (C SHell) – The C shell’s syntax and usage are very similar to the C programming language.

  • KSH (Korn SHell) – The Korn Shell also was the base for the POSIX Shell standard specifications etc.

Each shell does the same job but understand different commands and provide different built in functions.

Why do we need shell scripts.

  • To avoid repetitive work and automation

  • System admins use shell scripting for routine backups

  • System monitoring

  • Adding new functionality to the shell etc.

Advantages of shell scripts:

  • The command and syntax are exactly the same as those directly entered in command line, so programmer do not need to switch to entirely different syntax

  • Writing shell scripts are much quicker

  • Quick start

  • Interactive debugging etc.

Disadvantages of shell scripts

  • Prone to costly errors, a single mistake can change the command which might be harmful

  • Slow execution speed

  • Design flaws within the language syntax or implementation

  • Not well suited for large and complex task

  • Provide minimal data structure unlike other scripting languages. etc

initialization of Shell:

When you log in to the system, the shell undergoes a phase called initialization to set up the environment.

This is usually a two-step process that involves the shell reading the following files −

  • /etc/profile

  • profile

The process is as follows −

  • The shell checks to see whether the file /etc/profile exists.

  • If it exists, the shell reads it. Otherwise, this file is skipped. No error message is displayed.

  • The shell checks to see whether the file .profile exists in your home directory. Your home directory is the directory that you start out in after you log in.

  • If it exists, the shell reads it; otherwise, the shell skips it. No error message is displayed.

The .profile File

The file /etc/profile is maintained by the system administrator of your Unix machine and contains shell initialization information required by all users on a system.

The file .profile is under your control. You can add as much shell customization information as you want to this file. The minimum set of information that you need to configure includes −

  • The type of terminal you are using.

  • A list of directories in which to locate the commands.

  • A list of variables affecting the look and feel of your terminal.

You can check your .profile available in your home directory. Open it using the vi editor and check all the variables set for your environment.


The .bashrc File

“.bashrc” is a shell script that Bash shell runs whenever it is started interactively. The purpose of a .bashrc file is to provide a place where you can set up variables, functions and aliases, define our prompt and define other settings that we want to use whenever we open a new terminal window.


Comments


bottom of page