Skip to main content

Command Palette

Search for a command to run...

#Devops Day4

Published
•3 min read•View as Markdown

Hello, everyone, this is my Fourth blog started my day4 as AWS DevOps Engineer #90daysofchallenge with Shubham Londhe #devops #trainwithshubham.

Basic Linux Shell Scripting

Today I learned the following topics:

Advanced Linux and shell scripting

What is grep, awk, find

grep:-It is a global regular expression print. You can search something and find anything anywhere so you can use grep command. E.g. grep folder/etc/passwd for checking user account properties.

Awk:-Operates on a line-by-line basis, processing each line in a text file based on patterns that you specify. It is commonly used for tasks such as data extraction, reporting, and transformation. for E.g. awk '{print NR,$1,$2,$5}'

Find:-It is used for searching and locating files and directories based on various criteria. It is particularly useful when you need to search for files in a directory hierarchy that meet specific conditions. For e.g. find /path/to/search -name <filename>

Let Discuss Shell Scripting

A shell Scripting is a list of command in a computer program that is run by the Unix shell. Which is command line interpreter. Commands are return line by line is called script. Shell Scripting is a sequence of shell command. It allows for the automation of repetitive tasks and the creation of custom utilities to streamline workflow on the command line.

For e.g. #!/bin/bash

echo "Hello, Guyss!"

What is kernel?

It is the heart the of the Linux. The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system. E.g. In window we click->Right->New folder-> Create as same in Linux we can give command it create a folder. This process is know as kernel.

#Task:-

1.Explain in your own words and examples, what is Shell Scripting for DevOps.

Ans: A shell scripting is a powerful tool that allows us to automate tasks and streamline processes in the world of devops. A shell Scripting is a list of command in a computer program that is run by the Unix shell. Which is command line interpreter. Commands are return line by line is called script. Shell Scripting is a sequence of shell command. It allows for the automation of repetitive tasks and the creation of custom utilities to streamline workflow on the command line.

For e.g.:- For e.g. #!/bin/bash

echo "Installing $1"

2.What is #!/bin/bash? can we write #!/bin/Sh as well?

Ans:-#!/bin/bash it is also knows as the shebang or hashbang , and it specifies the interpreter to be used for execution the script. In this case,/bin/bash refer to the Bash shell which is used in Linux and Unix System. It is possible to use #!/bin/sh This shebang tells the system to use the bourne shell to interpret the script. both option are used but its important to choose the appropriate one base on your specific requirement.

3.Write a Shell Script which prints I will complete #90Days0ofDevOps challenge

Ans:-#!/bin/bash

echo "I will complete #90Days0ofDevOps challenge".....

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

Ans:-'''bash

#!/bin/bash

echo "Enter your name:"

read name

echo "Your name is:$name"

echo "Arguments 1:$1"

echo "Arguments 2:$2

'''

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

Ans:-''''bash

#!/bin/bash

n1=10

n2=40

if[$n1 -gt $n2]

then

echo "$n1 is greater than $n2"

else

echo""$n1 is less than or equal to $n2"

fi

'''

More from this blog

LinuxBlog1

50 posts