Basic Linux Shell Scripting for DevOps Engineers
What is Shell Scripting for DevOps?
Shell scripting for DevOps is the practice of writing small programs or scripts using a scripting language (like Bash or PowerShell) to automate tasks and processes in the field of DevOps.
Think of it as creating a set of instructions that a computer can follow to perform repetitive or complex tasks automatically. These scripts interact with the operating system and tools to configure servers, deploy software, manage infrastructure, and perform various other tasks involved in the DevOps workflow.
By using shell scripting, DevOps professionals can save time and effort by automating tasks that would otherwise be done manually. This helps in achieving faster and more consistent deployments, reducing human error, and streamlining workflows. Shell scripting is an essential skill for DevOps practitioners as it enables them to automate routine operations and focus on more strategic and value-added activities.
What is #!/bin/bash? can we write #!/bin/sh as well?
The #!/bin/bash is called a shebang or hashbang. It is the first line in a shell script and indicates the interpreter or shell to be used to execute the script. In this case, #!/bin/bash specifies that the script should be interpreted and executed using the Bash shell.
Yes, you can write #!/bin/sh instead of #!/bin/bash. The /bin/sh refers to the system's default shell, which may or may not be Bash. On most Linux distributions, /bin/sh is typically a symbolic link to the Bourne shell or a compatible shell such as Bash, Dash, or Ash.
Using #!/bin/sh instead of #!/bin/bash allows your script to be more portable and compatible with different shells. However, keep in mind that some advanced features or syntax specific to Bash may not be available if you use #!/bin/sh.
If you specifically require certain Bash features or syntax in your script, it's recommended to use #!/bin/bash to ensure compatibility. Otherwise, if your script doesn't depend on Bash-specific features, using #!/bin/sh is generally a good choice for better portability across different systems and shells.
Write a Shell Script which prints I will complete #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
#author : Ajay patel
#Date : 26 april 2023
#version :1.0
# Take user input
echo "Enter your name:"
read name
# Take command-line argument
argument=$1
# Print variables
echo "User input: $name"
echo "Command-line argument: $argument"
Write an Example of If else in Shell Scripting by comparing 2 numbers?
#!/bin/bash
#author : Ajay patel
#Date : 26 april 2023
#version :1.0
# Read input numbers from command line
read -p "Enter Number 1: " num1
read -p "Enter Number 2: " num2
# Compare the numbers using if-else
if (( num1 == num2 )); then
echo "The numbers are equal"
elif (( num1 > num2 )); then
echo "Number 1 is greater than Number 2"
else
echo "Number 1 is less than Number 2"
fi
This was the task for 4th days of challenge.It was quite easy .If you have any questions please write in the comment.
Happy learning.



