Operating System - HP-UX
1827459 Members
3810 Online
109965 Solutions
New Discussion

setting the variable in the script

 
sheevm
Regular Advisor

setting the variable in the script

Hi,

I am setting a variable in the script and using it later to process something. When I echo the variable it has value. But actually when I use it looses it value. But when I harcoded the value instead of exported variable name it worked.

O.S IS hp-ux 11.23

Has anyone aware of this type of a problem?

EX: export JAVA_DIR=/opt/java1.4/jre
$JAVA_DIR does not work.

If I hard code /opt/java1.4/jre IT WORKS.

Thanks
Raji
be good and do good
6 REPLIES 6
Sandman!
Honored Contributor

Re: setting the variable in the script

You need to echo the variable to use its value i.e.

# export JAVA_DIR=/opt/java1.4/jre
# echo $JAVA_DIR
/opt/java1.4/jre
Victor Fridyev
Honored Contributor

Re: setting the variable in the script

If you want to set a variable in a script and to use it out of the script, you have to work in a shell, called from within the script.
Can you please explain the problem more detailed ?
Entities are not to be multiplied beyond necessity - RTFM
OldSchool
Honored Contributor

Re: setting the variable in the script

w/o the code, or least the "broken" part, its hard to tell what's going on.

"$JAVA_DIR" doesn't work? What are you expecting it to do and what if anything does "echo $JAVA_DIR" say?

If it's blank, are you:

Running a script then checking after it finishes? If so, I'd expect it not to be set, as you did it in a separate process and it went away when the script finished. the fix for this one "source" or "dot" the script when you run it. as in ". ./mystuff.sh"

Are you running a script that runs another script to set it. in this case, in the initial script, source or dot the second script as noted above
Arturo Galbiati
Esteemed Contributor

Re: setting the variable in the script

Hi Raji,
please, post the peice of code that doesn't work to further help.
Rgds,
Art
Prasanth V Aravind
Trusted Contributor

Re: setting the variable in the script

i think that , you need to issue " echo $JAVA_DIR " to see the variavle value.

if you still facing the problem plese send the script


Regards
Prasanth
Prasanth V Aravind
Trusted Contributor

Re: setting the variable in the script


Hi Raji,


Plaese try like this


[root@steelmatrix ~]# export JAVA_DIR=/opt/java1.4/jre
[root@steelmatrix ~]# echo $JAVA_DIR
/opt/java1.4/jre
[root@steelmatrix ~]#


Regards
Prasanth