1

I have 2 shell scripts. In the first script I have kept the main method. In the 2nd script I have placed all the variables needed for the method since they are too many. Actually the main method needs 8 variables to run, likewise I have some 10 sets of 8 variables. The main method in script1 has to run for every set of variables. My questions:

How to call these variables from script 2 to the main method in script 1 in order to execute the same? Can I try declaring each set of variables as a function and try to call inside script 1? How to do that?

Please help me with this. Thank you in advance.

2 Answers 2

6

you can keep the common variables alone in one script, say var.sh and add

. var.sh #dot Space var.sh

in all the scripts where the variables are needed

Sign up to request clarification or add additional context in comments.

4 Comments

@Venky, if this answer works for you, you can reward Vignesh by accepting the answer.
I already mentioned I have a main method in script1 which has to run for each set of variables in script2. I want to run the main script again and again for each set of variables(var1 to var8 since the main method utilises 8 variables to run). How to make this happen? Please share some ideas.
I am not very clear with the question. but i will try to answer. just keep the variables and the definition of the main method in the first script but dont call it there. Now load the script as i ve done above and call it in the required scripts
@Vignesh This works, but why? I tried previously using ./var.sh and it didn't.
0

I had a similar issue.
Thanks to Vignesh I made the following changes that worked for me:

Originally the variables were localized w/in the __RequestLogin.sh script:

#!/bin/bash
# Loading Data

sh __RequestLogin.sh
sh __ExecuteScript.sh

This Updated script allowes access to these variables w/in __ExecuteScript.sh:

#!/bin/bash
# Loading Data

. __RequestLogin.sh
. __ExecuteScript.sh

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.