Accessing variables of one shell script in another shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Accessing variables of one shell script in another shell script
# 1  
Old 04-30-2007
Accessing variables of one shell script in another shell script

Hi All,

I have a shell script called sample1.sh where I have 2 variables. Now I have another shell script called sample2.sh. I want the variables in sample1.sh to be available to sample2.sh.

For example. In sample1.sh I am finding the sum of 2 numbers namely a and b. Now I want to access these variables in sample2.sh. Is this possible? How can I do this?

Thanks in advance.
# 2  
Old 04-30-2007
Quote:
Originally Posted by rsendhilmani
Hi All,

I have a shell script called sample1.sh where I have 2 variables. Now I have another shell script called sample2.sh. I want the variables in sample1.sh to be available to sample2.sh.

For example. In sample1.sh I am finding the sum of 2 numbers namely a and b. Now I want to access these variables in sample2.sh. Is this possible? How can I do this?

Thanks in advance.
sample2.sh
Code:
. sample1.sh
.....

If you have only variables in sample1.sh, then you can use above code, else keep all the variables in one file and replace sample1.sh by that file name in above code.
# 3  
Old 03-17-2009
Bug

export the variable u want to use

eg export var1

If value of var1 is set in 1.sh u can use the value of var1 in 2.sh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

2. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX for Advanced & Expert Users

Accessing secured server using shell script

Hi, I was trying to connect secure server using SFTP, but end up in error. Im looking for a shell script which will connect my secured FTP server For EG: hostname = example.com username = fed password = pass port = 993 Destination = web Push some tar file into web folder which is in... (3 Replies)
Discussion started by: Paulwintech
3 Replies

4. UNIX for Advanced & Expert Users

Accessing PL/SQL OUT variables in Korn Shell Script

Hello All, I was just wondering if there is any direct way to access PL/SQL OUT variables from Korn Shell Script. I could already figure out how to return a single value back from PL/SQL to Shell Script (using bind variable). But, what if we want to return multiple values? One option I... (4 Replies)
Discussion started by: bright_future
4 Replies

5. Shell Programming and Scripting

Accessing php script from shell script

Hi I'm a newb to php scripts. My task requires me to run a shell script from within the php script which I believe I've figured out. What I'm trying to do now is output something to the web page from the called shell script. when I use "echo" from the called shell script I don't get any output... (3 Replies)
Discussion started by: airon23bball
3 Replies

6. Shell Programming and Scripting

problem accessing Multiple Variables from C Program to a Shell script

program name--test #!/bin/bash output1=`/home/user/a.c` output2=`/home/user/a.c` k=`$output1 + 1` m=`$output2 + 1` echo $k echo $m --------------------------------------------------------------------------- prgram name--a.c #include<stdio.h> int main() (1 Reply)
Discussion started by: sameworld1980
1 Replies

7. Shell Programming and Scripting

Accessing aliases within a shell script

I am not able to access the aliases in my environment within a Python script. If I pass the alias to os.system(), I get a message saying "sh: x: not found". I've tried sourcing my .bashrc file in the script, but this does not work. I would perfer not to source my or any rc file because this... (9 Replies)
Discussion started by: cooldude
9 Replies

8. Shell Programming and Scripting

Problem in accessing variables outside shell

Hi, I have a shell script wherein i am doing some file operations and storing the data in some variables. I am exporting these variables as i need to use them outside shell. Then within the shell i am launching GDB session hoping that i will be able to access the exported variables in the GDB... (2 Replies)
Discussion started by: jsantosh
2 Replies

9. Shell Programming and Scripting

Accessing variables of one shell script in another shell script

I have a variable $exe in a shell script file a.sh which I need to access in another shell script file b.sh. How can I do that? :rolleyes: Thanks!! (2 Replies)
Discussion started by: looza
2 Replies

10. Shell Programming and Scripting

Accessing the parameters of a shell script

Hi, I have one situation. I am developing a shell script to which parameters will be passed from a Web based User Interface using some Business Process(BP).There are some 6 parameters for which user will enter the values in UI. These values will be passed to script by BP in the form -... (2 Replies)
Discussion started by: The Observer
2 Replies
Login or Register to Ask a Question