Day 1 of BashBlaze-7-Days-of-Bash-Scripting-Challenge
Challenge is marked here: BashBlaze-7-Days-of-Bash-Scripting-Challenge/Challenges/Day_1/Day_1_Basics.md at main · prajwalpd7/BashBlaze-7-Days-of-Bash-Scripting-Challenge · GitHub
Kindly use the above for your learning.
We will be performing the following 6 challenges on Day 1:
The general task of first creating a shell script:
Create a file using vim and .sh extension:
Save the file and make the file executable:
-
run the file
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.
There are two types of comments in shell scripts. First is single-line ones placed using "#" symbol at the start of the row.
The second is by using " : ' '
Note that : needs to start with a space at the beginning.
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.
We print messages using echo :
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.
We directly declare the variables using "variablename=" and use them using"$variablename"
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.
I have used the expr to create the sum of two numbers.
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.
I have used echo, ls and date variables:
Giving the following output:
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.
We have the following files:
Using the following script to find all files with name starting with "file":
Final output for Day 1 looks like below
Thank you and happy learning. See you at Day 2 of the challenge.