Linux - Shell Script
What is a Shell Script or shell scripting
Normally shells are interactive. It means the shell will accept command from you (via keyboard) and execute them. However, if you store a sequence of commands to a text file and tell the shell to execute the text file instead of entering the commands, that is known as a shell program or shell script.
A Shell script can be defined as - "a series of command(s) stored in a plain text file". A shell script is similar to a batch file in MS-DOS, but it is much more powerful compared to a batch file.
Shell scripts are a fundamental part of the UNIX and Linux programming environment.
Each shell script consists of
- Shell keywords such as if..else, do..while.
- Shell commands such as pwd, test, echo, continue, type.
- Linux binary commands such as w, who, free etc..
- Text processing utilities such as grep, awk, cut.
- Functions - add frequent actions together via functions. For example, /etc/init.d/functions file contains functions to be used by most or all system shell scripts in the /etc/init.d directory.
- Control flow statments such as if..then..else or shell loops to perform repeated actions.
Each script has purpose
- Specific purpose - For example, backup file system and database to NAS server.
- Act like a command - Each shell script is executed like any other command under Linux.
- Script code usability - Shell scripts can be extended from existing scripts. Also, you can use functions files to package frequently used tasks.
Did you know?
- It is the shell that lets you run different commands without having to type the full pathname to them even when they do not exist in the current directory.
- It is the shell that expands wildcard characters, such as * or ?, thus saving you laborious typing.
- It is the shell that gives you the ability to run previously run commands without having to type the full command again by pressing the up arrow, or pulling up a complete list with the history command.
- It is the shell that does input, output and error redirection..
Source: https://bash.cyberciti.biz/guide/What_is_a_Shell_Script_or_shell_scripting