Day 4:Shell Scripting in DevOps🚀🔍
Taking on the Day#4 of the #90DaysOfDevOps Challenge! 💪

Experienced QA professional with a passion for manual and automation testing. Proficient in DevOps practices, ensuring seamless integration and continuous delivery. Dedicated to ensuring top-notch software quality and efficiency. Eager to contribute my skills to Hashnode's vibrant tech community. Let's collaborate and create exceptional experiences!
👋Introduction
Hey everyone, welcome again to my blog where we'll explore the magical world of Shell Scripting in DevOps. Don't worry !! we'll keep it simple, fun, and interactive! 😃🚀
🔍What is Shell Scripting for DevOps?🤔
Shell Scripting is like the superpower that every DevOps engineer needs in their arsenal. It's a way to automate tasks and run commands on your computer without the need for clicking around like a mouse ninja. Instead, we can use text-based scripts written in a shell language (like Bash) to do all the heavy lifting for us!💪
Imagine you're preparing breakfast 🍳. You could manually toast bread, fry eggs, and make coffee each morning, but that's time-consuming! With Shell Scripting, you can create a "Breakfast Automation" script that does it all with just one command. Voilà! Breakfast is served, and you can focus on more important DevOps tasks. 🥐
🔍What is #!/bin/bash?🤔
The Mysterious #!/bin/bash (also known as a shebang) is like the secret decoder ring of your script. It tells your computer which shell interpreter to use when executing the script. In this case, we're telling it to use the Bash shell, which is widely used and loved by DevOps folks.
🔍Can we write #!/bin/sh as well?🤔
Absolutely! #!/bin/sh will use the default system shell, which might also be Bash or another compatible shell. Using #!/bin/sh makes your script more portable, as it'll work on systems where Bash is not the default shell. It's like speaking a universal language in the DevOps galaxy! 🌌
📝So, Let's Write Some Shell Scripts!
✅Shell Script which prints the text "I will complete #90DaysOofDevOps challenge"📥🖨️
Step 1: Begin by generating a script file named filename.sh using Vim, ensuring it has a .sh extension.
Step 2: Add a shebang #!/bin/bash & appropriate command to display the desired text on the terminal within the script :
echo "I will complete #90DaysOofDevOps challenge"
Step 3: Save the script file and make it executable by executing the following command in the terminal:
chmod 777 filename.sh
Step 4: Finally, run the script in the terminal to display the intended statement:
./filename.sh

✅Shell Script to Take Input from Arguments and Print Variables📥🖨️
Step 1: Begin by creating a script file named filename.sh using vim, ensuring it has a .sh extension.
Step 2: First of all Add a shebang #!/bin/bash
Step 3: Now write arg1=$1, arg2=$2, arg3=$3: These 3 lines assign the first three command-line arguments to variables arg1, arg2, and arg3, respectively. When you run the script with arguments, these variables will store the corresponding values.
Step 4: Then write echo command to print the number of arguments through a variable that stores the number of command-line arguments passed to the script $#
echo "Number of arguments: $#"
Step 5: Now write echo command to print the values of the variables arg1, arg2, and arg3, which contain the first three command-line arguments, respectively.
echo "Argument 1: $arg1"
echo "Argument 2: $arg2"
echo "Argument 3: $arg3"
Step 6: Save the script file and make it executable by executing the following command in the terminal:
chmod 777 filename.sh
Step 7: Finally, run the script in the terminal with 3 argument values
./filename.sh arg1 arg2 arg3

✅Shell Script with If-Else (e.g Comparing Two Numbers)📥🖨️
Step 1: Write the shebang #!/bin/bash at the beginning of the script
Step 2: Use the echo command to display messages on the screen, prompting the user to enter two numbers. The read command is then used to read the user's input and store it in the variables num1 and num2.
echo "Enter the first number:" read num1
echo "Enter the second number:" read num2
we use an if-else statement to compare the values of num1 and num2. The square brackets [ ] are used for defining conditional expressions. The comparison operators used are > (greater than) and < (less than).
Step 3: Save the script file and make it executable by executing the following command in the terminal:
chmod 777 filename.sh
Note: Comments start with the # symbol in shell scripting and are ignored by the interpreter.

Step 4: Finally, run the script in the terminal

🎉Conclusion
Shell Scripting is a powerful tool for DevOps engineers to automate tasks and run commands efficiently. It saves time and effort by using text-based scripts. With the right scripts, you can automate processes like a breakfast ninja and focus on more important DevOps responsibilities. Happy scripting! 🚀🐚🔍
Thank you for taking the time to read this blog. I hope you found the information helpful and insightful. So please keep yourself updated with my latest insights and articles on DevOps 🚀 by following me on :
Hashnode: vishaltoyou.hashnode.dev
LinkedIn https://www.linkedin.com/in/vishalphadnis
So, Stay in the loop and stay ahead in the world of DevOps!
Happy learning and linux-ing🚀😊




