Skip to main content

Command Palette

Search for a command to run...

Basic Linux Shell Scripting for DevOps Engineers.

Published
2 min readView as Markdown
Basic Linux Shell Scripting for DevOps Engineers.
A

Hi, I am ARIJIT MANNA, I have prepared myself to be a solver of any problem. I am pursuing on Bachelor's in Electrical Engineering. My Main Objective Is To Enhance My Professional Skills, Capabilities, And Knowledge To An Organization Which Recognizes The Sale Of Hard Work And Trusts Me With Responses And Challenges. My Long-Term Goal Is To Achieve A Good Position Where I Can Build My Career And My Short-Term Goal Is To Get A Job In A Reputed Company Where I Can Use My Skills And Learn New Things.

It is a #day4 of #90DaysOfDevOps🐧

let's start 🚀

Before jumping into writing shell script we need to understand what is Linux shell scripting and what is shell scripting for DevOps 🙄

Linux shell scripting !!😳

A shell script is a computer program designed to be run by a Linux shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text.

now try to understand what is shell scripting for DevOps !!😃

Shell Scripting is a way to automate tasks in a Linux operating system. It is a sequence of code or text that contains commands as input from users and execute them. Shell Scripting is a program to write a series of commands for the shell to execute. A shell script is usually created for command sequences that a user needs to use repeatedly to save time.

What is #!/bin/bash?

#!/bin/bash is the first line of the script and is called Shebang. Shebang tells the shell to execute it via bash shell. Shebang is simply an absolute path to the bash interpreter.

Can we write #!/bin/sh as well?

Yes, we can use #!/bin/sh to specify the path to the Bourne Shell (sh) interpreter. The Bourne Shell is another commonly used shell in Unix-based operating systems.

Now the wait is over as well as we are ready to write our first shell script😃🤩

Write a Shell Script which prints I will complete the #90DaysOofDevOps challenge

ubuntu@ip-172-34-13-300:~/final-script$ vim task.sh

ubuntu@ip-172-34-13-300:~/final-script$ chmod 770 task.sh

ubuntu@ip-172-34-13-300:~/final-script$ ./task.sh

output :

I will complete the #90daysofdevops challenge

Write a Shell Script to take user input, input from arguments and print the variables.

ubuntu@ip-172-34-13-300:~/final-script$ ./c_l-arg.sh Thank you for reading this article

output :

$# :9

$$ :1020

$0:./c_l-arg.sh

$*: Thank you for reading this article

$@: Thank you for reading this article

$3:for

Write an Example of If else in Shell Scripting by comparing 2 numbers

ubuntu@ip-172-34-13-300:~/final-script$ vim if-else.sh

inside vim editor

#!/bin/bash

echo "enter the first number:"

read a

echo "enter the second number:"

read b

if [ $a -gt $b ]

then

echo "$a is greater than $b"

else

echo "$b is greater than $a"

fi

:wq

ubuntu@ip-172-34-13-300:~/final-script$ chmod 770 if-else.sh

ubuntu@ip-172-34-13-300:~/final-script$ ./if-else.sh

output :

enter first number: 10

enter second number: 20

20 is greater than 10

Thank you very much for giving your valuable time for reading this article !!☺😊

Arijit Manna