DevOps, Day - 4

DevOps, Day - 4

Basic Linux shell scripting for DevOps

Table of contents

No heading

No headings in the article.

What is Linux shell scripting?
Linux shell scripting is a way to tell your computer what to do by writing a set of commands in a file. When you run this file, the computer will execute the commands and perform tasks automatically. It's a useful tool for automating tasks and managing resources on a Linux or Unix-like operating system and can make your life easier by saving you time and effort.

What is shell scripting in DevOps?
. In DevOps, shell scripting is used to automate tasks and streamline workflows, such as configuring servers and deploying applications. It helps to ensure fast and efficient delivery of software products.
. They can also use shell scripts to monitor system resources and alert them if any issues arise.
. It allows DevOps engineers to write scripts that can be easily reused and scaled.

What is #!/bin/bash ?
#!/bin/bash is the first line in a shell script that tells the computer which program to use to interpret and execute the script.
. In this case, it tells the computer to use the Bash shell, which is a type of program that understands and executes the commands in the script.
. It's an important line because, without it, the computer wouldn't know how to execute the script.

What is #!/bin/sh ?
#!/bin/sh is called a "shebang" or "hashbang" and is used in shell scripts to specify the interpreter to be used to run the script.
. In this case, #!/bin/sh tells the operating system to use the Bourne shell as the interpreter for the script.
. The shebang line is used by the operating system to determine how to execute the script. It is a critical part of any shell script and must be included for the script to function properly.

Can we use #!bin/bash instead #!/bin/sh and viceversa
Yes, you can use #!/bin/bash instead of #!/bin/sh and vice versa in your script, but there are some differences between them.
. #!/bin/bash specifies that the script should run using the Bash shell interpreter, which may provide additional functionality that is not available in the standard Bourne shell (/bin/sh).
. #!/bin/sh specifies that the script should run using the system's default shell interpreter, which may or may not be Bash. Using #!/bin/sh can help ensure that your script is more portable to other systems, but it may not be able to take advantage of Bash-specific features and functionality.
. In general, it's a good idea to use #!/bin/sh if your script does not require any Bash-specific features, and to use #!/bin/bash if you need to use Bash-specific features.

Shell script to print any text of your choice
echo "Hi, I am excited to complete 90 days of Devops challenge!"

Shell Script to take user input, input from arguments and print the variable
echo "Enter any 2 numbers"
read n1 n2
sum = $(($n1+$n2))
echo "addition of $n1 and $n2 are $sum"

If-else in Shell Scripting by comparing 2 numbers
echo "Enter any 2 values"
read a b
if [[ $a > $b ]]
then
echo "$a is greater"
else
echo "$b is greater"
fi

Thank you so much for reading

Follow me at LinkedIn to see interesting posts like this : )

Linkedin

Β