Linux is built with certain powerful tools, which are unavailable in Windows. One of such important tool is Shell Scripting. Windows however comes with such a tool but as usual it is much weak as compared to it’s Linux Counterpart. Shell scripting/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages. In-fact automating these day-to-day task on server is an important task, system administrator has to perform and most of the admins achieve this by writing scripts to be executed as and when required.
The most commonly used shell in Linux is BASH which stands for Bourne Again Shell. Other Shell commonly found in Linux are:
- Almquist shell (ash)
- Bourne shell (sh)
- Debian Almquist shell (dash)
- korn shell (ksh)
- Public domain korn shell (pdksh)
- MirBSD korn shell (mksh)
- Z shell (zsh)
- Busybox, etc.
We have tried to cover a large variety of shell programming on a number of aspect in 5 different posts.
Understand Linux Shell and Basic Shell Scripting – Part I
I was a bit hesitating to write on scripting Language, as I was not sure if the users were going to accept it or not, but the response received is a history, in itself. We tried to provide you with the basic knowledge of scripting Language and how to use it, writing basic commands, Need of comment lines and how to write it, talking shebang, making a script executable and its’ execution.
The first and the introductory script was aimed to get a simple output, thus making you comfortable with the world of shell scripting.
The second script was there, to tell you how you can execute more than one command in a script, however not piped, at this stage.
The third and last script of this post was a simple but very much interactive script which ask for you first name, store it, again ask for your last name, store it and address you with your full name, and last name in different lines of output.
At the end of this post you were supposed to know how to execute Linux commands independently from a shell script, storing and manipulating data, as required and store data at the run-time.
Shell Script Part I : Understand Linux Shell and Basic Shell Scripting Language
Feeling proud with the response received on first article, writing next article of the series was the first thought, that hit my mind and hence the second article of the series was:
5 Shell Scripts for Linux Newbies to Learn Scripting – Part II
Very much clear from the caption, here 5-Shell Scripts were listed. But to list which kind of script here, was a cumbersome job for us. We thought to dedicate this post to design and colours in shell. Our principal thinking behind this was to tell you that Linux terminal is not boring and colourless and you can perform your task in a very much colourful manner.
The first script of this post draws a special pattern, say a diamond pattern with dots(.), the implementation of for loop here was what you learned from this specific script.
The second script of this post, provided you with the output of several colours. You learned certain colour codes (not necessary to memorise) changing the text and background colour individually and the learning process was very much colourful
The third article of this post was a script of less than 10 lines, but was a very useful script which encrypts a file/folder with password. Security implementation was never so easy ever. We didn’t write a decryption script here, but provided you with the command you need to decrypt a file/folder and ask you to write the decryption script yourself.
The fourth script of this post was a bit long script (long, at this point of learning) which reports server related information and can be redirected to a file for future reference. We utilised Linux commands in a pipelined fashion to get desired result and thus pipeline an important tool in scripting language, was in your knowledge.
The fifth and the last script of this post was a very useful script specially for web administrator, where automatic email will be send to user if the disk space crosses the limit. Let a user registered for 5 GB of web space and as soon as his web upload limit counts reaches 4.75 GB, an automatic email will be send to user for web space increment.
Shell Script Part II : 5 Shell Scripts to Learn Shell Programming
Sailing Through The World of Linux BASH Scripting – Part III
It was time to tell you about certain key words used and reserved in Scripting Language, so that we could refine our scripts in a very much professional manner. We discussed here, the implementation of Linux commands in shell script.
The first script of this post aimed to tell you how to move up a directory in shell script. Well during Linux package installation you would have seen that the file gets stored at several location, automatically and this script comes handy if you need any such task.
The second script of this post is a very useful script, and useful to Administrators. It can create unique file/folder automatically with date and time stamp, so as to remove any chance of overwriting data.
The third article of this post gathers information related to server and stores it into a text file, so that it could be sent/stored for future references.
The fourth article of this post converts data either from the file or standard input to lowercase in a one go.
The last article of this post is a simple calculator which is capable of doing four basic Mathematical operation interactively.
Shell Script Part III : Sailing Through The World of Linux BASH Scripting
Mathematical Aspect of Linux Shell Programming – Part IV
The mathematical theme based article is the result of an email I received, where a Linux Enthusiastic didn’t understood the last script of the third post, yup! The calculator script. Well to simplify the mathematical operations, we created independent scripts for individual mathematical operation.
Very much clear from the name this script performs addition of two numbers. We have used ‘expr’ to perform the operation.
Subtraction.sh, Multiplication.sh, Division.sh are second, third and fourth script of the post respectively which performs mathematical operations according to their name.
The fifth script of this post generates table of a number, which can be provided at run-time.
The next script of the post checks if a number input from standard input is odd or even and prints the result on standard output.
The seventh script of this post generates the factorial of a number. Calculating factorial on black and white (paper) is a painful task, but here it is a fun.
The script checks if a provided number is Armstrong or not.
The last script of this post check if a number is prime or not and generates the corresponding output.
Shell Script Part IV : Mathematical Aspect of Linux Shell Programming
Calculating Mathematical Expressions in Scripting – Part V
The first script of this post test if a number being entered is a Fibonacci or not.
The second script of this post converts Decimal Number to Binary. This is one of the most common project you would have had in your summer vacation assignments.
The third script of this post converts Binary Number back to decimal, just vice-versa of above process.
However, we didn’t wrote proper script for the below mathematical conversions but provided one liner command, so that you yourself can implement it in your own script.
- Decimal to octal
- Decimal to Hexadecimal
- Octal to Decimal
- Hexadecimal to Decimal
- Binary to Octal , falls into the above category.
Shell Script Part V : Calculating Mathematical Expressions in Shell Scripting Language
We have tested all the scripts, ourselves to ensure, every script you get runs 100% perfectly in your terminal. Moreover, we have included sample output in most of the scripts, so that you don’t gets confused.
Well that’s all for now, from me. I will be here again with an interesting article, you people will love to read. Till then keep connected to Tecmint. Stay Fit, Healthy and Tuned. Don’t forget to provide us with your valuable thoughts in comment, which is highly appreciated.
Latest posts by Avishek Kumar (see all)
- DNF – The Next Generation Package Management Utility for RPM Based Distributions - August 26, 2014
- 6 Interesting Funny Commands of Linux (Fun in Terminal) – Part II - August 23, 2014
- 15 Practical Examples of ‘echo’ command in Linux - August 21, 2014
Linux Services & Free WordPress Setup
Our post is simply ‘DIY’ aka ‘Do It Yourself, still you may find difficulties and want us to help you out. We offer wide range of Linux and Web Hosting Solutions at fair minimum rates. Please submit your orders by Clicking Here.