Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)
I have 2 shell scripts, a.sh, and the b.sh.

How can I call the b.sh from within a shell script named a.sh?

1 Answer

0 votes
by (36.8k points)
edited by

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

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jan 6, 2021 in Linux by blackindya (18.4k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...