How to access variables across scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to access variables across scripts
# 1  
Old 08-13-2007
How to access variables across scripts

Hi All,

I have declared a variable in script1 and assign a value for it. In script2 i'll call script1 and then I want the value of variables set in script1.

I have tried with export, but in vain.
How can I achive this?

Below is the two scripts.

--script1
#!/usr/bin/ksh

echo $1
JAVA_HOME=/opt/java1.4

export JAVA_HOME

--script2
#!/usr/bin/ksh

./setValue.sh

echo "Java is present: ${JAVA_HOME}"

In script2 JAVA_HOME is empty, but in script1 JAVA_HOME has value.

Pls. help me in this.

Thanks in advance
# 2  
Old 08-13-2007
Quote:
Originally Posted by javaDev
Hi All,

I have declared a variable in script1 and assign a value for it. In script2 i'll call script1 and then I want the value of variables set in script1.

I have tried with export, but in vain.
How can I achive this?

Below is the two scripts.

--script1
#!/usr/bin/ksh

echo $1
JAVA_HOME=/opt/java1.4

export JAVA_HOME

--script2
#!/usr/bin/ksh

./setValue.sh

echo "Java is present: ${JAVA_HOME}"

In script2 JAVA_HOME is empty, but in script1 JAVA_HOME has value.

Pls. help me in this.

Thanks in advance
In script2, you need to invoke the other script as

. ./setValue.sh instead of just ./setValue.sh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need to get out of 2 variables in scripts

Hi All, i have written below script, and out put i am looking for both variable PRIMARY_CONF and $STANDBY_CONF but i am getting below error d1.sh: line 64: ------------------------------ line 64 is: if -a ; then ---------------------------------- please let me know where is the... (9 Replies)
Discussion started by: amar1208
9 Replies

2. Shell Programming and Scripting

How to pass variables between scripts?

Hello, I have two bash scripts like the following: script 1: #!/bin/bash var=WORLD bash path/to/second/script/script2.bash script 2: #!/bin/bash echo "HELLO $var" I expected the output to be "HELLO WORLD" but instead, I get "HELLO". I understand that when I envoke another bash... (2 Replies)
Discussion started by: jl487
2 Replies

3. Shell Programming and Scripting

Passing variables between sub-scripts

I have written a program for some data analysis. It is gettin long. I would like to restructure it so that i can have a master file which controls multiple subscripts in order to make it easier to understand. I need to be able to define variables in the master script which are used by all three... (2 Replies)
Discussion started by: carlr
2 Replies

4. Shell Programming and Scripting

Restrict access to .ksh scripts

Hi, How to restrict access to a .ksh script in such the way that the users can only execute the script, neither read nor write. I tried the below code so that my user alone has the rwx and other users can only execute. chmod 711 sample.ksh But when I logged in as a different user... (26 Replies)
Discussion started by: machomaddy
26 Replies

5. Shell Programming and Scripting

using unix scripts database access

i want to access database (sql script) within a unix script. help me (2 Replies)
Discussion started by: chamaraa
2 Replies

6. Shell Programming and Scripting

Scope of variables between scripts

Friends, I am using ksh under SunoS. This is what I have In file1.sh NOW=$(date +"%b-%d-%y") LOGFILE="./log-$NOW.log" I will be using this file through file1.sh as log file. I have another script file2.sh which is being called inside my file1.sh. I would like to use the same log... (6 Replies)
Discussion started by: dahlia84
6 Replies

7. Shell Programming and Scripting

Passing variables between scripts

Hi all. I need to pass a value from a script that runs in a sub-shell, back into the calling shell like below (or into script 2 directly): outer_script export param=value1 script1 $param (in script1: export param=value2) script2 $param ($param is now value1, not value2... (4 Replies)
Discussion started by: bbergstrom74
4 Replies

8. UNIX for Dummies Questions & Answers

Passing variables between scripts...

Hey all, I'm wondering how you pass variable's that are defined in one script to another script that's been called by that first script..... Best regards, Jaz (1 Reply)
Discussion started by: Jazmania
1 Replies

9. UNIX for Dummies Questions & Answers

Variables in scripts

Just a quick question. If I have a script that calls another script while running, is it possible for the second script to reference a variable in the first script and if so, how. Is it scriptname.sh:$VARIABLE for a global variable and can you do scriptname.sh:function $VARIABLE or am I off my... (1 Reply)
Discussion started by: kirkm76
1 Replies

10. Cybersecurity

scripts access

hi got some hosting web space on a server, my question is I am part of a user group and my concern is that of security where by other users in the group can go into my cgi directory and look at my scripts and files and get user passwords etc.How do you prevent access(copying) to these scripts or... (3 Replies)
Discussion started by: steve hodkin
3 Replies
Login or Register to Ask a Question