As we know the bash script is very very important for System Administrator. They are performing lots of tasks using Bash script.

Today, In this tutorial we will learn how to add a bash script into another Bash script.

We will learn it in 4 simple steps, where we create two simple scripts and use one script into another script.

Step 1 – Create a configuration script
Step 2 – Create the main script
Step 3 – Add configuration script into the main script
Step 4 – Execute the main script

Create a configuration script

First, we create a script with below content and save it with the name of “config.sh”.

Create the main script

Now, we will create another script with below content and save it with the name of “main.sh”.

Add configuration script into the main script

You can add one bash script into another bash script by using the “source” keyword, which is use to give reference to another script.

After adding “config. Sh” script into “main. Sh” script you main script will look like below script:

Execute the main script

Now, you can test the script by executing the main script. To execute script first assign the execute permission for both scripts and run the main script using “sh” or “bash” command, or you can run it like below also:

If You Like What We Do Here On LinuxConcept, You Should Consider:

Stay Connected to: Twitter | Facebook

Subscribe to our email updates: Sign Up Now

 

We are thankful for your support.

The Linux command SED stands for stream editor, and its use to do lot’s of operation on file for search, find and replace, insert new text, and delete after seeing the pattern.

The most common use of SED command which a System administrator or engineer doing every day is text substitution or find and replace text.

Why is SED command essential to find and replace text as we can do it in vi, vim editor quickly? Well, the answer is, the SED command do these operations easily without opening the file, which is more important when you are dealing with data in a script or within any extensive process where text replacement is a small part of your whole automated task.

Suggested Reading: Linux sed command Structure

Examples:

We will use below created file as an input for sample command

Replacing String

Replacing or Substituting string is find string in a file and replacing that string with another one.

The below command will help you to substitute string in file “linuxconcept.txt” without open the file.

Output:

Here in the above command, “s” is indicating SED command used for substituting string, and “/” is used as delimiters. The text “Linux” is a search pattern here, and the “UNIX” is replacement string.

In default SED command only replace the first occurrence of a string in each line and not replacing the string if it comes in second, third …. times in the same line.

Replacing all the occurrence in file

To replace all find string in a file, you can use the “/g” substitute flag in command, here “g” is for “global” substitution.

Output:

If You Like What We Do Here On LinuxConcept, You Should Consider:

Stay Connected to: Twitter | Facebook

Subscribe to our email updates: Sign Up Now

 

We are thankful for your support.

Follow me

SATISH KUMAR

I am Satish Kumar, Founder of LinuxConcept. Linux and F.O.S.S enthusiast, love to work on open source platform and technologies.
Follow me