Basic Linux Shell Scripting for DevOps Engineers
What is Shell Scripting for DevOps
Shell scripting for DevOps refers to the process of automating tasks related to the deployment, configuration, and management of software applications using command-line interface (CLI) scripts written in shell programming languages such as Bash, Zsh, and Fish.
For example, suppose a DevOps engineer needs to deploy a new version of an application to a server. In that case, they can write a shell script that automates the entire deployment process, including fetching the latest code from a repository, installing necessary packages, configuring environment variables, and restarting the application server.
What is #!/bin/bash?
can we write #!/bin/sh
as well
#!/bin/bash
is called a "shebang" or "hashbang," and it is used at the beginning of a shell script to indicate the interpreter that should be used to execute the script. In this case, the shebang #!/bin/bash
indicates that the Bash shell should be used to interpret and execute the commands in the script.
Yes, it is also possible to use #!/bin/sh
as the shebang in a shell script, which indicates that the script should be interpreted and executed using the default shell on the system (usually a variant of the Bourne shell). However, there are differences between Bash and other shells like sh or dash, so the functionality of the script may vary depending on the shell used.
Write a Shell Script that prints I will complete the #90DaysOofDevOps challenge
#!/bin/bash
echo "I will complete #90DaysOfDevOps challenge"
Write a Shell Script to take user input, input from arguments and print the variables
#!/bin/bash
echo "Enter your name: "
read name
echo "Name: $name"
Write an Example of If else in Shell Scripting by comparing 2 numbers
#!/bin/bash
num1=60
num2=50
if [ $num1 -gt $num2 ]
then
echo "Number 1 is greater than Number 2"
else
echo "Number 2 is greater than Number 1"
fi