Shell Scripting: Priyanka Suryawanshi
Shell Scripting: Priyanka Suryawanshi
Priyanka Suryawanshi
SHELL SCRIPTING
• Shell Scripting is an open-source computer program designed to be
run by the Unix/Linux shell.
• A shell in a Linux operating system takes input from you in the form of
commands, processes it, and then gives an output. It is the interface through
which a user works on the programs, commands, and scripts. A shell is accessed
by a terminal which runs it.
• When you run the terminal, the Shell issues a command prompt (usually
$), where you can type your input, which is then executed when you hit the Enter
key. The output or the result is thereafter displayed on the terminal.
• The Shell wraps around the delicate interior of an Operating system protecting it
from accidental damage. Hence the name Shell.
TYPES OF SHELL
• There are two main shells in Linux:
1. The Bourne Shell: The prompt for this shell is $ and its derivatives are listed
below:
• POSIX shell also is known as sh
• Korn Shell also knew as sh
• Bourne Again SHell also knew as bash (most popular)
2. The C shell: The prompt for this shell is %, and its subcategories are:
• C shell also is known as csh
• Tops C shell also is known as tcsh
HOW TO WRITE SHELL SCRIPT IN LINUX/UNIX
• On your Linux system, open a text editor program, open a new file to
begin typing a shell script or shell programming, then give the shell
permission to execute your shell script and put your script at the
location from where the shell can find it.
• File Execution permission
chmod +x filename.sh
./filename.sh
WHAT ARE SHELL VARIABLES?
• Variables store data in the form of characters and numbers.
• Similarly, Shell variables are used to store information and they can
use by the shell only.
SAMPLE SCRIPT
SHELL SCRIPT FILE PROGRAM
comm COMMAND
comm [options] file1 file2
The comm command compares 2 sorted files and produces 3 columns of output,
separated by tabs:
• cut uses tab as a default field delimiter but can also work with other delimiter by
using -d option.
• To extract the useful information you need to cut by fields rather than columns.
• With the -l option, ls will list out files and directories in long list format.
• In command -t option is used to sort directories and files by time and date of
creation or modification.
head COMMAND