Basic of bash scripting


Here we will cover the basics of bash scripting.

Task1: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. for example:-

#!/bin/bash

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

Task2: 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.

Syntax: echo [string]

echo "Scripting is fun with me"

Task3: 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.

variable1="hello"

variable2="bash"

Task4: Using variables

Now that we 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.

greeting="$variable1, $variable2"

echo "$greeting Welcome to the world of Bash scripting!"

Task5: using built in variables

Bash provides several built-in variables that hold useful information. This task is to create a bash script that utilizes at least three different built-in variables to display relevant information.

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"

Task6: Wildcard

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.

echo "Files with .txt extension in the current directory:"

ls *.txt

screenshot:

basic bash script

Note:

#Make sure to provide execution permission with the following command:

#chmod +x script.sh

Happy scripting!





要查看或添加评论,请登录

Rakesh Kumar的更多文章

  • Docker...

    Docker...

    Container: A container is a standard unit of software that packages up code and all its dependencies so the application…

  • Docker..

    Docker..

    What is container? A container is a standard unit of software that packages up code and all its dependencies so the…

  • Git and GitHub...

    Git and GitHub...

    Login aws account----> create two EC2 instance Commands:- sudo su #for admin command apt-get update -y #to update…

  • GIT and GitHub....

    GIT and GitHub....

    Version control system Stages of git/workflow Stages of git and its terminology Introduction: It is the software…

  • Interactive file and explorer

    Interactive file and explorer

    description:- we will create a bash script that serves as an interactive file and directory explorer. The script will…

社区洞察

其他会员也浏览了