Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have several shell scripts that I summarised within a global script. I am using some variables that are the same across all scripts, and I wrote a separate script for this, which I am sourcing in each sub-script. This is what my variables script looks like:


My global script, global.sh, looks like this:

source variables.sh
bash script1.sh
bash script2.sh

Now, I need to change the NUMBER variable in my variables script, run the global script, change the number, run the global script again etc. for each number from 6-15. At the moment I am doing this manually every time the global script has finished, but it's taking up a lot of time.

Has someone got an easy to implement tip for a newbie?

Thanks in advance!

share|improve this question
up vote 1 down vote accepted

First you have to adapt variables.sh so that NUMBER is not set unconditionally any more:


That allows you to pass the value from the calling process:

for((NUMBER=6;NUMBER<16;NUMBER++)); do
  source variables.sh
  bash script1.sh
  bash script2.sh

General remark: I am surprised that this works without export statements or set -a.

share|improve this answer
My script is indeed executed 10 times now, but the problem is, it inputs the number 6 for the variable every time, not numbers from 6-15. – Kaly Jun 1 '14 at 19:34
@Kaly You have modified variables.sh as I told you? – Hauke Laging Jun 1 '14 at 19:36
Yep, I placed NUMBER=${NUMBER:-6} into my script, and also replaced the other "NUMBER"s inside variables.sh with ${NUMBER:-6}. Maybe that was wrong? – Kaly Jun 1 '14 at 19:38
@Kaly You should replace only the NUMBER= line. It shouldn't cause problems in the other positions, though. For debugging put a line echo $NUMBER at the beginning of variables.sh. – Hauke Laging Jun 1 '14 at 19:43
Sorry about that! It still didn't work, but I placed an "export" before "NUMBER=" and now it works perfectly. Thanks so much! – Kaly Jun 1 '14 at 20:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.