Day 8 :- 🖥️ Exploring Bash Scripting Fundamentals

Day 8 :- 🖥️ Exploring Bash Scripting Fundamentals

Day 8 :- TASK

Article content

• 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
<<readme
info: this script will give you date and time
readme

#this script will print date and time

#print the current time and date
echo "Date and time is $(date)"

#print welcome message
echo "Welcome to scripting challenge"

#end of script        
Article content

• 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.

#!/bin/bash
<<readme
info : this file will print use of echo
readme


echo "Hello everyone this is my day08 of devops jounrey stay tuned"        
Article content

• 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.

#!/bin/bash


name="Anand Raval"
challenge="90DaysOfDevops"        
Article content

• 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.

#!/bin/bash


read -p "Enter value of A:" a
read -p "Enter value of B:" b

sum=$((a+b))

echo "$a+$b=$sum"        
Article content

• 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

echo "Current loged in user:$USER"
echo "Home directory:$HOME"
echo "Current shell:$SHELL"        
Article content

• 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

#!/bin/bash


echo "printing all list of directories"

ls *.txt        
Article content

Thank you for reading!

© 2024 Anand Raval. All rights reserved.

To view or add a comment, sign in

More articles by Anand Raval

Insights from the community

Others also viewed

Explore topics