- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Shell Script?
A shell script is a list of commands in a computer program that is run by the Unix shell which is a command line interpreter. A shell script usually has comments that describe the steps. The different operations performed by shell scripts are program execution, file manipulation and text printing. A wrapper is also a kind of shell script that creates the program environment, runs the program etc.
Types of Shells
There are two major types of shells in Unix. These are:
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.
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
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.
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.
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.
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.
Advantages of Shell Script
Some of the advantages of shell script are −
- The commands and syntax of the shell script are the same as that entered at the command line. Because of this, there is no need to switch to a completely different syntax.
- It is much faster to write a code in shell script than in other programming languages. This also means that the program is easier to create and files required can be selected easily.
- Shell script can also be used to provide linkage for already existing programs.
- Shell scripting can be used by users that are not experts to modify and tailor the behaviour of their programs according to their requirements.
Disadvantages of Shell Script
Some of the disadvantages of shell script are −
- There may be errors in shell scripting that prove to be quite costly.
- The programs in shell script are quite slow while executing and a new process is required for every shell command executed.
- Different platforms in shell scripting may also have compatibility problems.
Example of Shell Script
A script demo.sh is created for this example. The script and commands are given as follows −
#!/bin/bash gzip zip find echo
gzip is a command to create, extract or view .gz files,
zip is a command used to create or extract zip file,
find is a command that is helpful to search for a file,
echo is a command displays a line of text
- Related Articles
- Get output of MongoDB shell script?
- Use result from MongoDB in shell script?
- How to terminate a MongoDB shell script earlier?
- Aborting a shell script on any command fails
- Showing a GUI Notification From a Shell Script in Linux
- Storing a Command in a Variable in a Shell Script
- Running a Shell Script on a Remote Machine Through SSH
- A Shell Script to Send Email Alert When Memory Gets Low
- How to Count Word Occurrences in a Text File using Shell Script?
- How to Insert a New Line Character in Linux Shell Script Output ?
- A Shell Script to Monitor Network, Disk Usage, Uptime, Load Average and RAM
- What is the snail shell made of?
- What is the MySQL user creation script?
- What is Pre-Request Script in Postman?