We help IT Professionals succeed at work.
Get Started

Shell source or dot command question

RegProctor
RegProctor asked
on
340 Views
Last Modified: 2013-12-26
Hi,

I'm at the point with my first shell script where it will be worth breaking it up into multiple scripts.

Suppose I had 4 scripts support1, support2, support3 and main (all .sh scripts).

Now suppose support2 needs support1 and support3 also needs support1 and main needs support 2 & 3. This means in both support 2 & 3 scripts I would put '. ./support1.sh' and in main I would include scripts 2 & 3. Are there issues with this that I should be aware of? For example, will global variables in support1 set outside functions be set every time support1 is called/loaded?

In PHP these issues are resolved by use of "require_once" vs "require" (or the equiv. include cmds.) I don't see such commands in bash (I'm using OpenSuSE 11.0 which defaults to the bash shell).

Perhaps there is an "if script 'xxx' is loaded type command you can do so you only load a script once as needed? Or perhaps it doesn't matter? Perhaps there is a particular way that scripts work or are written that makes all this unimportant?

In any case, could someone please enlighten me?

Thanks.

Comment
Watch Question
sysadmin
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 3 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE