If you want to automate regular tasks and make your life easier, using shell scripts is a good option. This article introduces you to the basic concepts that will help you to write efficient shell scripts.
![Shell-scripting][1]
Ashell scriptis acomputer programdesigned to be run by theUNIX shell, acommand-line interpreter. The various dialects of shell scripts are considered to bescripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing of text. A script that sets up the environment, runs the program, and does any necessary cleanup or logging, is called awrapper.
### Identification of shell prompt
You can identify whether the shell prompt on a Linux based computer is a normal or super user by looking at the symbols of the prompt in the terminal window. The ‘#’ symbol is used for a super user and the ‘$’ symbol is used for a user with standard privileges.
![Figure 1: Manual of date command][2]
### Basic commands
The script comes with too many commands that can be executed on the terminal window to manage your computer. Details of each command can be found in the manual included with the command. To view the manual, you need to run the command:
```
$man <command>
```
A few frequently used commands are:
```
$date #display current date and time
$cal #display current month calendar
$df #displays disk usages
$free #display memory usage
$ls #List files and directories
$mkdir #Creates directory
```
Each command comes with several options that can be used along with it. You can refer to the manual for more details. See Figure 1 for the output of:
```
$man date
```
### Redirection operators
The redirection operator is really useful when you want to capture the output of a command in a file or redirect to a file.
Brace expansion is one of the powerful options UNIX has. It helps do a lot of operations with minimal commands in a single line instruction. For example:
```
$echo Front-{A,B,C}-Back
Front-A-Back, Front-B-Back, Front-C-Back
$echo {Z..A}
Z Y X W V U T S R Q P O N M L K J I H G F E D C B A
$mkdir {2009..2011}-0{1..9} {2009..2011}-{10..12}
```
This creates a directory for 12 months from 2009 to 2011.
### Environment variables
An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. This variable is a part of the environment in which a process runs.
| script filename | capture all command execution in a file |
Tips:
> History : CTRL + {R, P}
> !!number : command history number
> !! : last command
> !?string : history containing last string
> !string : history containing last string
```
export HISTCONTROL=ignoredups
export HISTSIZE=10000
```
As you get familiar with the Linux commands, you will be able to write wrapper scripts. All manual tasks like taking regular backups, cleaning up files, monitoring the system usage, etc, can be automated using scripts. This article will help you to start scripting, before you move to learning advanced concepts.