Shell Scripting is an open-source designed to be travelingthe Unix/Linux shell. Shell Scripting program a series of commands for the shell to execute. It can combine lengthy and repetitive sequences of commands into script be stored and executed anytime which, reduces programming efforts.
What is Shell?
Shell UNIX term for an interface between a user and an service. Shell provides users with an interface and accepts human-readable commands into the system and executes those commands run automatically the program’s output shell script.
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 sh
- Korn Shell also known as sh
- Bourne Again SHell also known as bash (most popular)
2. The C shell: The prompt for this shell , and its subcategories are:
- The c shell csh
- Tops C shell tcsh
How to Write Shell Script in Linux/Unix
Shell Scripts are written using text editors. On your Linux system, open a text , open file typing a shell script or shell programming, then give the shell permission to execute your shell script and put your script in from where the shell can find it.
Choosing A Text Editor
Shell scripts are text-based files. your scripting journey, choose a text editor that works best for you. Linux distributions pre-installed text editors, but commonly used ones are listed below:
- vi – Usually installed by default. Preferred by administrators because editor small in size .
- emacs – contains of features but beginner-friendly
- pico – a simplified version of emacs (without the features)
- nano – a pico but comes with features
Let us understand the steps in creating a Shell Script:
- Create a file vi editor(or editor). Name script file with extension .sh
- Start the script with #! /bin/sh
- Write some code.
- Save the script file 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.