About Shell Scripting
About Shell Scripting
What is Script?
- A script or Scripting Language is a programming language for a special run-time environment that automates the execution of the task.
- The task could alternatively be executed one-by-one by a human operator using CLI on the command prompt screen.
What is Shell?
- Shell is a command language interpreter that executes commands read from the standard input device (keyboard) or a file.
- Shell is an interface between user and kernel
- Shell is an environment in which we can run our commands, programs, and shell scripts.
- A shell provides you with an interface to the Unix System. It gathers input from you and executes the program based on that input.
- Shell read your Input after you press Enter. It determines the command you want to be executed by looking at the first word you enter.
What is Shell Scripting?
A script or Scripting Language is a programming language for a special run-time environment that automates the execution of the task.
Shell Scripting is run by the Unix/Linux shell and it’s a series of commands written in plain text. The task could alternatively be executed one-by-one by a human operator using CLI on the command prompt screen.
Why do we use shell Scripting?
1. shell script can be used to prepare input files, job monitoring, and output processing.
2. useful to create own commands.
3. save lots of time on file Processing.
4. to Automate some tasks of day-to-day life.
5. System Administration part can be also automated.
6. Daily Application backup and monitoring.
7. Reduce Admin Workload.
8. Can manage a lot of servers from any single place using shell scripting.
Types Of Supported Shell in Linux
• Bourne shell (sh) ⏩ /bin/sh
• Bourne Again Shell (bash) ⏩ /bin/bash
• Korn Shell (ksh) ⏩ /bin/ksh
• C shell (csh) ⏩ /bin/csh
• Turbo C shell (tcsh) ⏩ /bin/tcsh
How we can write Any Script?
Script files are always divided into three Parts:
- Shebang OR Header
- Comment Section
- Program body
Shell Scripts: are written using text editors. 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.
Let us understand the steps in creating a Shell Script:
- Create a file using a vi editor (or any other editor). Name script file with extension .sh
- Start the script with #! /bin/sh
- Write some code.
- Save the script file as filename.sh
- For executing the script type bash filename.sh
“#!” is an operator called shebang which directs the script to the interpreter location. So, if we use” #! /bin/sh” the script gets directed to the bourne-shell.
Typical procedures performed by shell Script
A shell is a command-line interpreter and typical operations performed by shell scripts include file manipulation, program execution, and printing text. Shell scripts have several required constructs that tell the shell environment what to do and when to do it.
The main idea behind concocting a Shell Script
It is said to be the combination of long and repeatable command sequences into one script so that it can be executed as and when required. The main idea behind creating a shell script is to lessen the load of the end-user.