Shell Scripts 🤠

Shell Scripts 🤠

I recently learned about shell scripts. This blog is about shell scripts🙂.

·

2 min read

Why Shell Scripts?

  • Shell scripts help to automate things in Linux and it is very helpful:
  • Automate daily backups.
  • Automate installation and patching of software on multiple servers.
  • Monitor the system periodically.
  • It also helps in troubleshooting and audits.

Who is this for?

Shell Scripts are very helpful and also time-saving but who is this for?

    1. System Administrators.
    1. Developers.
    1. IT Engineers
    1. DevOps Engineers.

But anyone can learn this because it is simple to learn and just it has some basic rules to follow like loops and functions.

Before learning Shell Scripts you have basic knowledge of Linux and its commands. But don't worry no programming knowledge is required to learn that.

  • Types of the shell.

    1. The Bourne Shell (sh)
    1. The GNU Bourne-Again Shell (bash)
    1. The C Shell (csh)
  • 4.The Korn Shell (ksh)

We have different types of Shell but we only talk about The GNU Bourne-Again Shell (bash).

Creating your first script - To create your first script open your terminal and type vi my-first-scripts then you type your scripts inside the vi editors and save them. Then after making the script give permission to the file type in terminal chmod 777 myfirstscripts and after giving permission just run the script using ./myfirstscripts command. You have to give a decent name to your script file like my-first-scripts so this is the best practice to make scripts.
  • VARIABLES

Variables are defined in CAPITAL LETTERS. We can see these variables by using the command “$“

Example:

#!/bin/bash

A=10
B=20

sum=$(( $A + $B ))

echo "Sum is: $sum"

So here is a simple addition script here we can take variables as A and B and then use them as $A and $B.

  • Variable names must be in lowercase with underscores to separate words.

good: mission_name

bad: Mission_Name, Mission Name, Mission-name

So this is basically about the shell script after this blog. I will write about SHEBANG, EXIT Codes, And Conditional statements.

Â