Shell Scripting Challenge #Day-8

Shell Scripting Challenge #Day-8

Shell Scripting Tutorials: Day 8 Challenge

Task 1: Comments

In bash scripts, comments are used to add explanatory notes or disable certain lines of code. Your task is to create a bash script with comments explaining what the script does.

#!/bin/bash

# First line of the script is the shebang which tells the system how to execute

Task 2: Echo

The echo command is used to display messages on the terminal. Your task is to create a bash script that uses echo to print a message of your choice.

# Task  2: Echo
echo "Scripting is fun with Nikks @TWS DevOps Batch 7"

Task 3: Variables

Variables in bash are used to store data and can be referenced by their name. Your task is to create a bash script that declares variables and assigns values to them.

# Task  3: Variables
variable1="Hello"
variable2="Bash"

Task 4: Using Variables

Now that you have declared variables, let's use them to perform a simple task. Create a bash script that takes two variables (numbers) as input and prints their sum using those variables.

# Task  4: Using Variables
greeting="$variable1, $variable2"
echo "$greeting Welcome to the world of Bash scripting!"

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.

# Task  5: Using Built-in Variables
echo "My current bash path - $BASH"
echo "Bash version I am using - $BASH_VERSION"
echo "PID of bash I am running - $$"
echo "My home directory - $HOME"
echo "Where am I currently? - $PWD"
echo "My hostname - $HOSTNAME"

Task 6: Wildcards

Wildcards are special characters used to perform pattern matching when working with files. Your task is to create a bash script that utilizes wildcards to list all the files with a specific extension in a directory.

# Task  6: Wildcards
echo "Files with .txt extension in the current directory:"
ls *.txt

Create a single bash script that completes all the tasks mentioned above.

#!/bin/bash

# First line of the script is the shebang which tells the system how to execute

# Task  2: Echo
echo "Scripting is fun with @TWS"

# Task  3: Variables
variable1="Hello"
variable2="Bash"

# Task  4: Using Variables
greeting="$variable1, $variable2!"
echo "$greeting Welcome to the world of Bash scripting!"

# Task  5: Using Built-in Variables
echo "My current bash path - $BASH"
echo "Bash version I am using - $BASH_VERSION"
echo "PID of bash I am running - $$"
echo "My home directory - $HOME"
echo "Where am I currently? - $PWD"
echo "My hostname - $HOSTNAME"

# Task  6: Wildcards
echo "Files with .txt extension in the current directory:"
ls *.txt

Result:

Conclusion

Mastering shell scripting is a valuable skill for anyone working in a Unix-like environment. Through this challenge, you have learned how to use comments to document your code, utilize the echo command to display messages, declare and use variables, perform arithmetic operations, leverage built-in variables for useful information, and employ wildcards for pattern matching. By combining these tasks into a single bash script, you have gained practical experience that will enhance your scripting capabilities and improve your efficiency in managing and automating tasks. Keep practicing and exploring more advanced features to further hone your skills.

Thanks for reading. Happy Learning !!

Connect and Follow Me On Socials :

LinkedIn|Twitter|GitHub

Like👍 | Share📲 | Comment💭