Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Calling function in another bash script

Writer Matthew Harrington

Let's say; Script a.sh has function f1 defined. Script b.sh needs to call f1 to use. How do I do that? I searched online, it says I have to edit some PATH vairable, but does it mean global PATH or is there any PATH specifically used only in bash?

1 Answer

In b.sh:

source a.sh

That will make the function available to be called within b.sh.

The source command (also known as the . command) executes a.sh in b.sh's shell, so if you only want that function, you'll have to extract it into c.sh, and both a.sh and b.sh will have to source c.sh

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy