Bash Scripting


Hello everyone, in today’s article we are going to discuss about Bash scripting. Bash scripting is kind a programming language which is often used in command line.

Bash scripting is used by the System administrators, Network Engineers, Developers, Scientists and etc … and mainly who are more into bug-bounty field who likes to automate things which are required in the recon process.

In this article, I will try to cover all parts which are required.

Bash scripting is a text file which contains a list of commands which we use in Linux or Unix. Bash Helps by executing all the commands by replacing it with a single command.

How to create a bash script?

First, we need to create a single text file. For that we are going to a use a command which is going to create blank text file.

            Command:      touch

In the above command we had touch command, which going to create a blank text file. And the name for the bash file we used is

The bash script can run successfully with .sh and without .sh extension for the file.

We had successfully created the file.

 Now, it’s time to add some contents in the file.

How to write contents in the bash script?

Ok, till now we had learned how to create a blank bash script file.

Now, first.

The bash script should start with

#! /bin/bash  à This should be in the top of the bash script file.

# – it is bash

! – it is bang.

/bin/bash – and followed by the path of the bash.

I hope you have cleared why we should keep at the top or first in the bash file.

I am going to create a file to print Hello World.

Before that,

I am using Nano (A Text Editor for command line interface). You can use whichever suits you, there are some other text editors. Like vim, gedit, mousepad, sublime, and notepad. The text editors mentioned before, some are graphical based, and some are command line based.

In bash scripting to print something, we need to use “echo” command.

            Command: echo “Hello World”

I had added the command to print Hello World. Now, save the file.

Before, running the file. We need to give the script file executing permissions. Because, a normal text file doesn’t have executing permissions.

So to give permission for executing the text file. We need to use a command called chmod.

Command: chmod +x

Here is the detailed explanation about the above command,

Chmod -> it is the command which is going to help change the permissions of the file.

+x -> it is telling to give execution permission for the file.

I had given permission for the file, to execute.

Now, it’s time to execute the bash file.

So, to execute the bash file. We are going to use a command.

Bash  à This command will help to execute to bash file.

Successfully, we had print “Hello World”.

What Next?

We had successfully learned how to create a blank text file, how to add contents to the file using command line how to change permissions of the file, and how to execute the bash file.

In this article, I will help you to create a script for subdomain enumeration using different tools.

I hope this will be helpful for those who are going to do subdomain enumeration using different tools and combine all. And I was the same person who did that. But, after learning bash I was able to create a script that helped to do subdomain enumeration with different tools with a single command.

Before going to create this script, you need to know somethings.

mkdir a It is a command which is used to create a directory.

Now, let’s start creating the script.

First, I will give you the script and then I will explain all the things which are used in the script.

I would say, this is not a great tool. But this is an example script that will help you to create your own script for subdomain enumeration.

#! /bin/bash

# $1 =>

mkdir $1

cd $1

mkdir subdomain_outputs_$1

cd subdomain_outputs_$1

echo -e “\e[1;32mEnumerating subdomains using amass \e[0m”

amass enum –passive -norecursive -noalts -d $1 -v -o amass_$1.txt

echo “”

echo -e “\e[1;32mEnumerating subdomains using assetfinder \e[0m”

assetfinder –subs-only $1 | tee -a assetfinder_$1.txt

echo “”

echo -e “\e[1;32mEnumerating subdomains using subfinder \e[0m”

subfinder -d $1 -o subfinder_$1.txt

echo “”

echo -e “\e[1;32mEnumerating subdomains using knockpy \e[0m”

knockpy $1 -o knockpy_$1

echo “”

echo -e “\e[1;32mEnumerating subdomains using findomain \e[0m”

findomain -t $1 -u findomain_$1.txt

echo “”

#combining all the subdomain finder outputs

echo “\e[1;33mCombining all the outputs into one”

cat amass_$1.txt assetfinder_$1.txt subfinder_$1.txt findomain_$1.txt | sort -u | tee -a domain_$1.txt

This is the script, that will help you to collect subdomains from different tools without wasting much time, running different tools by running this tool.

You can also add other tools if you want too.

  1. First, I had #! /bin/bash – which should be the first line of the bash script.
  2. $1 – it is an argument which helps you to insert the domain name in the command itself.

I will give an overview of the script.

  1. First you need to give the command as bash
    1. After that, it will start executing.
    1. Now, it will create a folder name as
    1. Next it will create another folder subdomain_outputs.
    1. After that it will start finding subdomains using different tools one by one.
    1. Later, after completing. It will combine all the outputs into a single file by removing duplicates.

This is how the tool works.

echo -e “\e[1;32mEnumerating subdomains using amass \e[0m”  — This will make the printed text into green text.

You can find this code from GitHub Through:

I hope everyone understood. How to create a blank text file, how to add contents through command line, changing the permissions to execute the file, and how to run the bash file.

If you have any doubts, feel free to comment down below.

Thank You.