"Day 4 DevOps Challenge -  Exploring Basic Linux Shell Scripting" ๐Ÿš€๐Ÿ’ป๐Ÿ“

"Day 4 DevOps Challenge - Exploring Basic Linux Shell Scripting" ๐Ÿš€๐Ÿ’ป๐Ÿ“

ยท

4 min read

What is a Shell? ๐Ÿš

A shell is a friendly interface between you and your computer's operating system. It's like a virtual assistant that understands your text-based commands and helps you interact with the system. You can think of it as a way to talk to your computer using everyday language.

What is Linux Shell Scripting? ๐Ÿš€๐Ÿ’ป

Linux Shell Scripting is a way of automating tasks by writing a series of commands in a script file. It's like giving your virtual assistant a list of instructions to follow automatically. Instead of typing each command one by one, you can write them all in a script and run it. The shell reads the script and executes all the commands for you, saving time and effort.

๐Ÿ“ Getting Started with Shell Scripting for DevOps! ๐Ÿ˜Ž

Hello there, fellow noobs! ๐Ÿ˜„ If you're new to the world of DevOps and feeling a bit overwhelmed by all the jargon and technical terms, fear not! In this blog, we'll break down the basics of Shell Scripting and make it easy-peasy for you to understand. ๐Ÿš€

What is Shell Scripting for DevOps? ๐Ÿš€๐Ÿ’ป๐Ÿง™โ€โ™‚๏ธ

Shell Scripting is like having a superpower for automating tasks in the DevOps world. ๐Ÿง™โ€โ™‚๏ธ It's a way of writing simple scripts (sets of instructions) that can be executed in the command-line interface of your computer. These scripts help developers and system administrators perform repetitive tasks efficiently, saving time and effort.

Example:

Let's say you want to automate the process of deploying a new version of your software. With Shell Scripting, you can write a script to handle all the necessary steps, such as pulling the latest code from the repository, building it, and deploying it on the server.

What is #!/bin/bash? Can we write #!/bin/sh as well? ๐Ÿค”๐Ÿ’ญ๐Ÿ”

When you see "#!/bin/bash" at the top of a shell script, it means that the script should be interpreted and executed using the "bash" shell. Bash (Bourne Again SHell) is a popular shell with powerful features. But yes, you can use "#!/bin/sh" instead, which refers to the default shell on many systems. It might not have all the fancy features of bash, but it's more portable across different platforms.

Writing a Shell Script to complete the #90DaysOfDevOps challenge: ๐Ÿš€๐Ÿ’ป๐Ÿ“

Let's get our motivation game strong! Here's a simple script to print a commitment message for the #90DaysOfDevOps challenge:

#!/bin/bash

echo "I will complete #90DaysOfDevOps challenge"

To use this script, follow these simple steps:

  1. Save the script in a file, for example, name it "motivation.sh".

  2. Make the script executable by running the command: chmod +x motivation.sh.

  3. Run the script using the command: ./motivation.sh.

  4. The script will display the commitment message! ๐ŸŽ‰

Taking User Input and Using Arguments in Shell Scripting: ๐Ÿ“ฅ๐Ÿ”ข๐Ÿ“

Shell scripts can also interact with users and accept input from them. You can use the read command to take input from the user during script execution.

Here's an example:

#!/bin/bash

# Taking user input
echo "What's your name?"
read name
echo "Hello, $name! Welcome to the world of DevOps."

When you run this script and provide your name as an argument, it will greet you and display the arguments you passed.

Example of If-Else in Shell Scripting ๐Ÿ”„๐Ÿ”๐Ÿ”€

Conditional statements like If-Else are super useful in Shell Scripting. They allow us to make decisions and execute different code blocks based on conditions.

#!/bin/bash

# Comparing two numbers
num1=10
num2=20

if [ $num1 -gt $num2 ]; then
    echo "$num1 is greater than $num2"
else
    echo "$num1 is not greater than $num2"
fi

In this example, we compare num1 and num2, and the script will display the appropriate message based on the comparison result.

In Conclusion: ๐ŸŽฏ๐ŸŒŸ๐Ÿš€

Shell Scripting is a powerful tool in the DevOps toolbox that can save time and make life easier for developers and system administrators. With a bit of practice and creativity, you can automate various tasks and make your DevOps journey smoother than ever! So, keep scripting and exploring the world of DevOps! ๐Ÿš€๐Ÿ’ป

Remember, even noobs can become experts with dedication and learning. Happy scripting! ๐ŸŒŸ๐ŸŽ‰ ( I am a noob too )

Did you find this article valuable?

Support Adarsh Jha by becoming a sponsor. Any amount is appreciated!

ย