Bash – ”Sourcing” script from another script

Johnny Rosenberg gurus.knugum at
Sun Jan 4 22:09:10 UTC 2015

Just wondering…
I have a script that does two different things related to each other. I
could say that the script does one thing in two distinct steps, so it feels
natural to split those things into two scripts.

However, the second part of the script use some variables that got its
values in the first part, so the second script would need to calculate
those variables again, which feels redundant.

Seems like ”source” would do the job, since it executes the script in the
same shell. I thought something like this:
SomeFunction "$SomeVariable"
AnotherFunction "$AnotherVariable"
SomeFunction () { Some action}
AnotherFunction () { More action }

I'm pretty sure it will work, but is this a good practice?
Is it better to keep everything in one file even if that file will be quite
Or is it better to just run the script in another shell sending it a lot of

Kind regards

Johnny Rosenberg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the ubuntu-users mailing list