Day 1 of the Bash Scripting Challenge! ๐ #TWSBashBlazeChallenge
โ๏ธ Introduction
Hello EveryOne, Today I'm starting a 7 Day's Bash Script Challenge organized by Shubham Londhe . Here every day we will dive into Script, If you are interested in this then you also join this challenge, where you will learn new things.
As we talk about our Day 1 challenge we will be learning about the basics of Bash Script, Without any further discussion we will start.
โ๏ธWhat is Bash Script?
Hey there! ๐ Imagine you have a magical fairy assistant ๐งโโ๏ธ that follows your every command! Well, that's kind of what a Bash script is! ๐
๐ป Bash is like a wizard ๐งโโ๏ธ who speaks computer language and can perform amazing spells on your computer! With a Bash script, you give the wizard a list of instructions written in a special language (Bash script), and he magically executes them one by one!
๐ The script is like a recipe ๐ฒ for the wizard. You write down all the steps you want him to follow, like "wave the wand," "mix the potion," and "cast the spell" ๐ช - those are your commands!
๐ Then, the wizard reads the recipe (your script) line by line, and BOOM! ๐ฅ Your computer starts doing all the cool stuff you asked for! It can create folders, move files, talk to other programs, and so much more!
โจ And the best part? You can reuse the same magical recipe over and over again to make the wizard perform the same spell! It saves you lots of time and effort! ๐ฐ๏ธ
๐ก So, when you hear about a "Bash script," think of it as a magical spellbook ๐ that lets you control your computer with just a few lines of special wizardry language! ๐งโโ๏ธ๐
Task:1 Comments
๐ Imagine you're writing a secret diary ๐, and you want to add little notes to remind yourself of what's happening in your adventurous journey. Well, that's exactly what comments are in a Bash script! ๐ฌ
๐ Comments are like hidden messages ๐ that you write in your script, meant only for you (and other wizards who read your code). They start with a special symbol, the "hashtag" or "pound sign" (#). It's like casting an invisibility spell on your words, so the computer ignores them completely! ๐ซ๐งโโ๏ธ
๐๏ธ So, when you want to remember what a particular part of your script does, or if you want to leave a clue for fellow wizards who might look at your code, you sprinkle these magical hashtags and share your thoughts! It's like leaving breadcrumbs in the enchanted forest of code. ๐ณ๐ฐ
๐ Here's the fascinating part: the spells you write in your script are spoken in the language of computers, but comments are your secret language, meant only for humans to understand! ๐ฃ๏ธ๐ป
๐ญ So, next time you're casting your Bash spells, remember to use the power of comments to keep track of your adventures and guide your fellow wizards through the mystical world of your code! ๐งโโ๏ธ๐
#!/bin/bash
# DevOps Engineer: This is a bash script that demonstrates basic concepts of bash scripting.
# Task 1: Comments
# - In this task, we will use comments to explain the script.
# Output a welcome message to the user
echo "Welcome to Day 1 of the Bash Scripting Challenge!"
Task:2 Echo
๐ฃ๏ธ Imagine you're a powerful sorcerer with a magical megaphone ๐ข that can make your voice echo throughout the entire kingdom! Well, that's exactly what the "echo" command does in a Bash script! ๐งโโ๏ธ๐ฌ
๐ป When you use the "echo" spell in your script, you're casting a charm that makes your words appear on the screen for all to see! It's like leaving sparkly messages ๐ that everyone can read, including other wizards and even your computer! ๐งโโ๏ธโจ
๐ Just like a fairy spreading fairy dust, "echo" sprinkles your words on the display, creating a magical connection between you and your computer. You can send greetings, share secret incantations, or display the results of your mystical calculations! ๐๐ฎ
๐ To cast the "echo" spell, you simply write "echo" followed by the words you want to share. Your computer listens carefully to your commands, and when it encounters "echo," it gleefully displays your message on the screen like a shimmering spell coming to life! ๐ชโจ
๐ญ So, when you want to communicate with your computer or let others in on your sorcery, just reach for the "echo" spell, and watch as your words fill the realm of code with wonder and enchantment! ๐๏ธ๐
#!/bin/bash
# DevOps Engineer: Task 2: Echo
# - In this task, we will use the 'echo' command to print a message.
# Output a welcome message to the user
echo "Welcome to Day 1 of the Bash Scripting Challenge!"
Task:3 Variables
๐ญ Imagine you're a clever magician ๐ฎ, and you have a magical box ๐ฆ where you can store all sorts of treasures! Well, in the realm of Bash scripts, that magical box is called a "variable"! ๐ฉ
๐งโโ๏ธ Variables are like containers that hold valuable information, just like your magical box holds precious gems and spells! They have unique names, and you can put different things inside them, like numbers, words, or even whole sentences! ๐๐ข๐ฃ๏ธ
๐ Whenever you need to remember something important during your magical incantations, you can store it in a variable. It's like labeling your potions, so you can easily find them later! โ๏ธ๐ท๏ธ
๐ And here's the exciting part: you can change the contents of your magical box whenever you like! So, if you need a new gemstone or a different spell ingredient, you can swap it out in a snap! ๐๐
๐ค Variables are like messengers ๐โโ๏ธ between your spells. They carry information from one part of your script to another, helping your spells work together harmoniously! It's like having magical assistants who can fetch and deliver things for you! ๐ฌ๐งโโ๏ธ
๐ก So, whether you're counting enchanted stars, storing the name of your magical pet dragon, or keeping track of your quest progress, variables are your trusty companions on this mystical coding adventure! ๐โจ
#!/bin/bash
# DevOps Engineer: Task 3: Variables
# - In this task, we will declare and use variables.
# Declare variables and assign values
name="Purushotam"
age=20
# Output the values of variables
echo "Name: $name"
echo "Age: $age"
Task 4: Using Variables
Now that we have declared variables, let's use them to perform a simple task. In this task, we will create a bash script that takes two variables (numbers) as input and prints their sum using those variables.
#!/bin/bash
# DevOps Engineer: Task 4: Using Variables
# - In this task, we will use variables to perform a calculation.
# Get user input for two numbers
read -p "Enter the first number: " num1
read -p "Enter the second number: " num2
# Calculate the sum of the two numbers
sum=$((num1 + num2))
# Output the result
echo "The sum of $num1 and $num2 is: $sum"
Task 5: Using Built-in Variables
Bash provides several built-in variables that hold useful information. Your task is to create a bash script that utilizes at least three different built-in variables to display relevant information.
#!/bin/bash
# DevOps Engineer: Task 5: Using Built-in Variables
# - In this task, we will use built-in variables.
# Output the current user
echo "Current user: $USER"
# Output the hostname
echo "Hostname: $HOSTNAME"
# Output the current working directory
echo "Current directory: $PWD"
Task 6: Wildcards
๐ Imagine you have a magical key ๐ that can unlock countless doors with just one turn. Well, that's precisely what wildcards are in a Bash script! They are like powerful, all-purpose keys that let you unlock and manipulate files and folders in the blink of an eye! ๐ช๐
๐๏ธ Wildcards are represented by special characters like the "asterisk" (*) and the "question mark" (?). When you include these mystical symbols in commands, the Bash wizard takes it as a sign to unleash their magic! โจ๐งโโ๏ธ
๐ The "asterisk" (*) is like a shooting star ๐ in the night sky. It matches any number of characters, allowing you to find files with mysterious and ever-changing names. It's like having a shape-shifter at your command! ๐๐งโโ๏ธ
๐ On the other hand, the "question mark" (?) is like a treasure map with missing pieces. It stands for just one unknown character, making it perfect for uncovering hidden files with puzzling names! It's like having a crystal ball to predict the unknown! ๐๐ฎ
๐ฐ With these wildcards, you can conjure spells like "list all the files that start with 's'," or "delete everything ending with '.txt'." Your commands become a symphony of mystery and discovery! ๐ถ๐
๐ก So, when you venture into the world of Bash scripts, don't forget to wield the power of wildcards! They are your trusty companions on this enchanting journey, helping you navigate the vast landscapes of files and directories with ease! ๐บ๏ธ๐งญ
Conclusion
In the enchanting world of Bash scripting, you have embarked on a magical journey filled with powerful spells and captivating adventures! ๐งโโ๏ธโจ
๐ก You learned the secret language of Bash, where variables act as mystical containers, holding the essence of your data and secrets close to your heart! ๐๐
๐ Command spells allowed you to wield the power of your computer, bending it to your will with every line you wrote! ๐๐๏ธ
๐ Wildcards became your all-purpose keys, unlocking doors to hidden files and folders, revealing the mysteries of the digital realm! ๐๏ธ๐
๐ฌ And amidst your spellbinding code, comments became your whispered confidants, guiding you through your own magical incantations and helping fellow wizards comprehend the secrets within! ๐๐ค
๐งโโ๏ธ Now, armed with this newfound knowledge, you can weave your own captivating Bash scripts, orchestrating symphonies of code that dance and sing in harmony! ๐ถ๐
So go forth, young sorcerer, and embrace the beauty of Bash scripting! Let your creativity soar as you conjure up amazing scripts, unlocking the full potential of your computer's magic! ๐งโโ๏ธ๐๐ฎ
Checkout My GitHub Repository for projects:
Thanks for reading this blog. If you like this blog and find helpful then share with your friends. Happy Learning.