Shell How to call one shell script from another shell script

0 votes

I have two shell scripts, a.sh and b.sh.

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


 

Apr 14, 2022 in Linux Administration by Soham
• 9,710 points
748 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

There are a couple of different ways you can do this with such as:

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

  2. Or call it with the source command (alias is .), like this:
    source /path/to/script

  3. Or use the bash command to execute it, like:
    /bin/bash /path/to/script

The first and third approaches execute the script as another process, so variables and functions in the other script will not be accessible.

The second approach executes the script in the first script's process and pulls in variables and functions from the other script (so they are usable from the calling script).

In the second method, if you are using exit in the second script, it will exit the first script as well. Which will not happen in the first and third methods.

answered Apr 20, 2022 by Rahul
• 9,680 points

edited Mar 5

Related Questions In Linux Administration

0 votes
1 answer

How to take input from user in bash script?

You can use if-else branch to check ...READ MORE

answered Jan 31, 2019 in Linux Administration by Omkar
• 69,220 points
1,260 views
0 votes
1 answer

How to send mail using linux shell script?

If you've already configured the server, with ...READ MORE

answered Jun 11, 2019 in Linux Administration by ajs3033
• 7,300 points
1,317 views
0 votes
2 answers

How do I use a shell script to SSH in to a remote machine to execute commands?

Sorry in advance for any formatting. Check out ...READ MORE

answered Feb 7, 2021 in Linux Administration by anonymous
17,524 views
0 votes
1 answer

How to unblock one IP from black list?

Hi@akhtar, To unblock your blacklisted IP address, you ...READ MORE

answered Jun 10, 2020 in Linux Administration by MD
• 95,460 points
834 views
0 votes
1 answer

How to delete one user from CentOS system?

Hi@akhtar, You can use userdel command to delete ...READ MORE

answered Jun 19, 2020 in Linux Administration by MD
• 95,460 points
1,181 views
0 votes
1 answer

How to run one command inside another command in Linux?

Hi@akhtar, You can run multiple commands in your ...READ MORE

answered Oct 15, 2020 in Linux Administration by MD
• 95,460 points
3,186 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Adding yes/no/cancel prompts in shell script

You can use the read command. Here's ...READ MORE

answered Mar 13, 2019 in Linux Administration by ajs3033
• 7,300 points
4,360 views
0 votes
1 answer

How to change the default shell in Linux?

1. Change the password file directly for ...READ MORE

answered May 24, 2019 in Linux Administration by Upasana
• 8,620 points
1,130 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP