Learning Shell Scripting Language: A Guide from Newbies to System Administrator

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.

Linux Shell Script Guide
Linux Shell Script Guide

The most commonly used shell in Linux is BASH which stands for Bourne Again Shell. Other Shell commonly found in Linux are:

  1. Almquist shell (ash)
  2. Bourne shell (sh)
  3. Debian Almquist shell (dash)
  4. korn shell (ksh)
  5. Public domain korn shell (pdksh)
  6. MirBSD korn shell (mksh)
  7. Z shell (zsh)
  8. 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.

Hello.sh

The first and the introductory script was aimed to get a simple output, thus making you comfortable with the world of shell scripting.

Process.sh

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.

Interactive.sh

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.

Special_patter.sh

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.

Colourfull.sh

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

Encrypt.sh

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.

Server-Health.sh

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.

Disk_space.sh

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.

up.sh

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.

Randomfile.sh

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.

Collectnetworkinfo.sh

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.

Convertlowercase.sh

The fourth article of this post converts data either from the file or standard input to lowercase in a one go.

Simplecacl.sh

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.

Addition.sh

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.

Table.sh

The fifth script of this post generates table of a number, which can be provided at run-time.

EvenOdd.sh

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.

Factorial.sh

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.

Armstrong.sh

The script checks if a provided number is Armstrong or not.

Prime.sh

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

Fibonacci.sh

The first script of this post test if a number being entered is a Fibonacci or not.

Decimal2Binary.sh

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.

Binry2Decimal.sh

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.

  1. Decimal to octal
  2. Decimal to Hexadecimal
  3. Octal to Decimal
  4. Hexadecimal to Decimal
  5. 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.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Avishek
A Passionate GNU/Linux Enthusiast and Software Developer with over a decade in the field of Linux and Open Source technologies.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

9 Comments

Leave a Reply
  1. Hi Team,

    I need to get the exact telnet output without any manual intervention

    -bash-4.2# echo exit | telnet localhost 22
    Trying ::1...
    Connected to localhost.
    Escape character is '^]'.
    Connection closed by foreign host.
    
    
    
    -bash-4.2#  telnet localhost 22
    Trying ::1...
    Connected to localhost.
    Escape character is '^]'.
    SSH-2.0-OpenSSH_7.4
    ^]==========
    

    Here when use telnet localhost 22 - SSH-2 OpenSSH_7.4 is showing , but in echo exit | telnet localhost 22 it's not showing

    Output : 
    bash-4.2# echo exit | telnet localhost 22
    Trying ::1...
    Connected to localhost.
    Escape character is '^]'.
    Connection closed by foreign host.
    telnet> quit
    Connection closed.
    -bash-4.2#
    
    Reply
  2. Hi, I have written a script with four commands. These four commands are taking backup of my servers. But when the script is running it’s taking so much RAM So that I want to RUN these commands one by one but the script file is one. is it possible?

    Reply
    • @Kundan,

      Instead using script, try to add individual commands to the cron jobs and run them specific time. This way you can keep your Linux server performance to stable..

      Reply
  3. Please think of this part of the title, “A Guide from Newbies to System Administrator.” Is this guide written by newbies for system administrators? I am sorry for bringing this to your notice, but I thought you might want to correct it.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.