How to pass values in one script from another script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass values in one script from another script?
# 1  
Old 10-13-2010
How to pass values in one script from another script?

Hi,
I am trying to make a script A which will install the build automatically.
At one point in this script it will call another script B.
This Another script B will have options like
1) go to main manu
2) Install package
3) Uninstall package
4) Exit

Now for installation purpose I have 4 packages to install and while pressing Key 2 I need to give a full path of that package...

So, my question here is when my script A will reach to point where script B will start how can I supply this key like 2 and different paths for package... So that script B will automatically completed.

Please let me know if you dont understand my issue.
# 2  
Old 10-13-2010
What is the point writing 2 scripts?
Or did I miss something?
# 3  
Old 10-13-2010
If I understood your problem, just pass the variables as arguments to script B:
Code:
# Script A calling script B:
key=2
packagePath="<PathToPackage>"
<PathToScriptB>/scriptB.sh "${key}" "${packagePath}"

# Script B parsing arguments:
key="${1}"
packagePath="${2}"


Is this what you are looking for?
# 4  
Old 10-13-2010
Your question is valid... But Actually I am from Testing team and Script B is runniing since ages so I dont want to touch script B.

I want to do something like by which instead of punching keys from my keyboard script A will automatically pass the values to script B.
# 5  
Old 10-13-2010
Maybe write the variables and values to a configuration file and load it by using one line in script B.

Code:
# Script A will write a file like:
# cat ./scriptB.cfg 
key=2
packagePath="<PathToPackage>"

# In scriptB, just add the following line:
. ./scriptB.cfg

Don't forget that the variables must have the same name!
# 6  
Old 10-13-2010
hhhmmmm felipe... I can try for the second option you suggested.
But I'm bit confused... I mean what we have to specify in config file
i.e.

Script A:
{Few other commands}
{sh script B}

Script B:
{Options and awk script and Blah blah}

config.file:
??
# 7  
Old 10-13-2010
Not exactly!

You will need to write the variables you want to overwrite in script B in a config file.
Code:
# Write the variables you want to overwrite in script B to the config file from script A
############
# In script A
############
scriptBConfigFile="<PathToConfigFile>/scriptB.cfg"
echo "key=2" > "${scriptBConfigFile}"
echo "packagePath=<PathToPackage>" >> "${scriptBConfigFile}"
############

############
# In script B
############
scriptBConfigFile="<PathToConfigFile>/scriptB.cfg"

. "${scriptBConfigFile}"

Is it clear now?

If it is not, check the "source" command man page or check this link: source or dot operator MAN Page
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pass values to a script on runtime on nohup mode?

Hi All, I have a script which takes three inputs while executing, I need to run that script on nohup mode, How to do so. Kindly help me with the syntax. (1 Reply)
Discussion started by: Sikkandar
1 Replies

2. UNIX for Beginners Questions & Answers

How to pass values to a script called from within another script in shell?

Ceiling Light - The Forgotten Element One of the highest details concerning using an LED ceiling panel essentially offer a fantastic dance floor which definitely makes the customers dance right away.They are a quite low cost method of something like a lighting solution, simple collection up,... (1 Reply)
Discussion started by: harveyclayton
1 Replies

3. UNIX for Beginners Questions & Answers

How to pass values to a script called from within another script in shell?

Need ideas on how to achieve the below. We have a script say "profile.sh" which internally calls another existing script called "name.sh" which prompts for the name and age of a person upon execution. When i run profile.sh how can i populate a pre-defined value from another file and pass that... (1 Reply)
Discussion started by: sankasu
1 Replies

4. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

5. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

6. Shell Programming and Scripting

Pass values from web form to shell script

Hi, is it possible to pass more values from web form like textbox to shell script and if yes,how to do that.:confused::confused::confused: (2 Replies)
Discussion started by: tdev457
2 Replies

7. Shell Programming and Scripting

How to Pass the Output Values from the PL/SQL Procedure to Shell Script?

hi, Could anyone tell me how to pass the output values of the PL/SQL procedure to Shell script and how to store that values in a shell script variable... Thanks in advance... (5 Replies)
Discussion started by: funonnet
5 Replies

8. Shell Programming and Scripting

How to pass pl/sql table values to shell script

Hello, i am using '#!/bin/bash', i want to make a loop in pl/sql, this loop takes values from a table according to some conditions, each time the loop choose 3 different variables. What i am not able to do is that during the loop i want my shell script to read this 3 variables and run a shell... (1 Reply)
Discussion started by: rosalinda
1 Replies

9. Shell Programming and Scripting

need help on shell script(to pass the values)

only the arguments that are written to the file, my script is (sh /u01app/wkf.sh"$start_no","$name","$Condition","$file_name") like that when ever I run my script I need to write into a new file every time, like wise I have upto10 files with different names.bec my $start_no and $name will... (1 Reply)
Discussion started by: sai123
1 Replies

10. UNIX for Dummies Questions & Answers

how to pass values from oracle sql plus to unix shell script

how to pass values from oracle sql plus to unix shell script (2 Replies)
Discussion started by: trichyselva
2 Replies
Login or Register to Ask a Question