Bash – ”Sourcing” script from another script

Karl Auer kauer at biplane.com.au
Sun Jan 4 22:50:51 UTC 2015


On Sun, 2015-01-04 at 23:09 +0100, Johnny Rosenberg wrote:
> I'm pretty sure it will work, but is this a good practice?

It'll work, but it introduces dependencies that are a bit hard to
follow.

If possible, I would refactor the scripts into three - one script
calc.sh that calculates the variable values, then two separate scripts
script1.sh and script2.sh that each source calc.sh.

It depends on how complicated/expensive those variables are to
calculate, and whether calculating them has side-effects.

> Is it better to keep everything in one file even if that file will be quite
> big?

If two scripts have a section that does the same thing in each script,
and that thing is non-trivila, it's generally a good idea to separate it
out and get it right once. Then if changes are ever needed, you only
have to change one place and it will be corrected in all the places that
use it.

Regards, K.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)
http://www.biplane.com.au/kauer
http://twitter.com/kauer389

GPG fingerprint: 3C41 82BE A9E7 99A1 B931 5AE7 7638 0147 2C3C 2AC4
Old fingerprint: EC67 61E2 C2F6 EB55 884B E129 072B 0AF0 72AA 9882





More information about the ubuntu-users mailing list