0% found this document useful (0 votes)
90 views

Shell Script

There are two main types of shells in Unix - the Bourne shell and C shell. Shell scripts allow users to automate repetitive tasks, program features like variables and loops, and act as shortcuts for system commands. To write a shell script, the file is given a .sh extension and made executable. Common examples of shell script applications include automating code compilation, running programs, file manipulation, and backups. A basic "Hello World" shell script is also demonstrated.

Uploaded by

Rough Metal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Shell Script

There are two main types of shells in Unix - the Bourne shell and C shell. Shell scripts allow users to automate repetitive tasks, program features like variables and loops, and act as shortcuts for system commands. To write a shell script, the file is given a .sh extension and made executable. Common examples of shell script applications include automating code compilation, running programs, file manipulation, and backups. A basic "Hello World" shell script is also demonstrated.

Uploaded by

Rough Metal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Types of Shells

There are two major types of shells in Unix. These are:

Bourne Shell
This is the default shell for version 7 Unix. The character $ is the default prompt for the
bourne shell. The different subcategories in this shell are Korn shell, Bourne Again shell,
POSIX shell etc.

C Shell
This is a Unix shell and a command processor that is run in a text window. The character
% is the default prompt for the C shell. File commands can also be read easily by the C
shell, which is known as a script.

Capabilities of Shell Script


The different capabilities of the shell script are −

 Batch jobs

o Several commands that would be entered manually in a command line


interface can be executed automatically using a shell script. This can be done
without the user needing to trigger each command separately.

 Programming

o There are many features in modern shell scripts that are only found in
sophisticated programming languages such as arrays, variables, comments
etc. Many complicated applications can be written in shell scripts using these
features. But there is a problem i.e. shell script languages don’t support
classes, threading etc.

 Generalization

o It is much more flexible to use loops, variables etc for multiple tasks in shell
script. An example of this is a Unix shell script known as bash, which converts
jpg images to png images.

 Shortcuts
o There is a shortcut provided by a shell script for a system command where
command options, environment settings or post processing apply. This still
allows the shortcut script to act as a Unix command.

Shell Scripting She-bang


The sign #! is called she-bang and is written at top of the script. It passes instruction to
program /bin/sh.

To run your script in a certain shell (shell should be supported by your system), start
your script with #! followed by the shell name.

Example:

1. #!/bin/bash
2. echo Hello World

Steps to write and execute a script


 Open the terminal. Go to the directory where you want to create your script.
 Create a file with .sh extension.
 Write the script in the file using an editor.
 Make the script executable with command chmod +x <fileName>.
 Run the script using ./<fileName>.

Examples of shell script applications


Using a shell script is most useful for repetitive tasks that may be time consuming to
execute by typing one line at a time. A few examples of applications shell scripts can be
used for include:

 Automating the code compiling process.


 Running a program or creating a program environment.
 Completing batch
 Manipulating files.
 Linking existing programs together.
 Executing routine backups.
 Monitoring a system.

# Hello World Program in Bash Shell

echo "Hello"

echo $SHELL

var1=9

pwd

ls -l

if [ "$var1" -ge 10 ]; then

echo "Bigger Number"

else

echo "smaller number"

fi

You might also like