Shell Scripting Challenge

This script will demonstrates practical use of comments, echo, variables, built-in variables, and wildcards in bash scripting.
#!/bin/bash
#Shell Scripting Challenge
#This script will demonstrates practical use of comments, echo, variables, built-in variables, and wildcards in bash scripting.
# 1. Comments
# Comments will help to undersatnd the scripts.
# There are two types of comments
# i> single line comments
# ii> multiline comments
# 2. Echo
# This command will help you to display message of your choice.
echo "Hello, Welcome to Shell Scripting Challenge"
# 3. variables
# It is used to store data of your choice like words,alphabets,and numbers etc.
# You can declare and assign data to variables.
name="Imran"
education="B.Tech"
echo "My name is $name, and i completed $education"
# Above the 'name' is variable and the value is 'Imran'
# To use variables need to use '$' and assign them into commands of your requirment
# 4. Using Variables
# Calculating sum of two numbers
num1=10 #First Number
num2=20 #Second Number
i=`expr $num1 + $num2` #Use the keyword 'expr' to perform arithmatic operations
echo "The sum of $num1 & $num2 is: $i" #Print the output
# Second method to calculate sum
sum=$((num1 + num2))
echo "The sum of $num1 & $num2 is: $i" #Print the output
# 5. Using Built-in Variables
# Bash provides several built-in variables that store useful information.
echo "The Current Working Directory is: $PWD" #Print the current working directory
echo "The Current logged in User ID is: $UID" #Print the User ID
echo "The Script file name is: $0" #Print the file name
# 6.Wildcards
# Wildcards are special characters used to perform pattern matching when working with files.
ls *.txt # List all the files who have .txt extension
Let’s breakdown the script:
Comments:
Comments begin with
#. They are usefull to undarstand code or any script.It is not executable by shell.
# This is a comment.Echo:
Echo print the text to terminal. You can print any text you want.
echo "Hello, Welcome to Shell Scripting Challenge"Variables:
Variables are used to store data.
name="Imran" education="B.Tech"Using Variables:
Performing arithmatic operations by using variables
num1=10 #First Number num2=20 #Second Number i=`expr $num1 + $num2` #Use the keyword 'expr' to perform arithmatic operationsOutput:
echo "The sum of $num1 & $num2 is: $i"Built-in Variables:
Bash provides several built-in variables that hold useful information.
$0holds the name of the script.$UIDgives the current logged in User ID.$PWDholds the current working directory.
echo "The Current Working Directory is: $PWD" #Print the current working directory
echo "The Current logged in User ID is: $UID" #Print the User ID
echo "The Script file name is: $0" #Print the file name
Wildcards:
Wildcards are special characters used to perform pattern matching when working with files.
ls *.txtThis command lists all files that match the pattern
*.txt(any file ending with.txt).
Happy Learning:)



