How to call one shell script from another shell script? (2024)

There are several ways of different ways you can do this:

Make the other script executable, add the #!/bin/bash line at a top, and a path where a file is to a $PATH environment variable. Then you can call it a normal command;

Or call it with a source command (alias is .) like

this: source /path/to/script;

Or use a bash command to execute it:

/bin/bash /path/to/script;

The 1st and 3rd methods execute a script as another process, so variables and functions in another script will not be accessible.

The second method executes a script in the first script's process and pulls in the variables and functions from other scripts so they are used from calling the script.

In the 2nd method, if you are using the exit in a second script, it will exit the 1st script as well. Which will not happen in the 1st and 3rdmethods.

Come and join Linux training to gain great knowledge.

Do check out the video below

How to call one shell script from another shell script? (2024)
Top Articles
Latest Posts
Article information

Author: Ouida Strosin DO

Last Updated:

Views: 6263

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Ouida Strosin DO

Birthday: 1995-04-27

Address: Suite 927 930 Kilback Radial, Candidaville, TN 87795

Phone: +8561498978366

Job: Legacy Manufacturing Specialist

Hobby: Singing, Mountain biking, Water sports, Water sports, Taxidermy, Polo, Pet

Introduction: My name is Ouida Strosin DO, I am a precious, combative, spotless, modern, spotless, beautiful, precious person who loves writing and wants to share my knowledge and understanding with you.