LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to set the variable (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-set-the-variable-766142/)

elainelaw 11-02-2009 01:39 AM

How to set the variable
 
I use the below command on the shell can set the variable , it works .

$export ORA=/opt/ora
echo $ORA
/opt/ora

$export JAVAHOME=/usr/java
echo $JAVAHOME
/usr/java

but if I add these two lines to a file , and then run it , it do not work .

can advise I have many varibles that want to be added to my current login , except run it one by one , what can i do ? thx

vinaytp 11-02-2009 01:55 AM

Hi elainelaw

open /etc/bashrc file and add

Code:

$export ORA=/opt/ora
$export JAVAHOME=/usr/java

execute

Code:

source /etc/bashrc
Hope this helps.....
Cheers !!!

AnanthaP 11-02-2009 02:21 AM

You know,I googled and THIS was th first result.

http://www.linuxquestions.org/questi...script-344057/

End

elainelaw 11-02-2009 02:45 AM

Quote:

Originally Posted by vinaytp (Post 3740880)
Hi elainelaw

open /etc/bashrc file and add

Code:

$export ORA=/opt/ora
$export JAVAHOME=/usr/java

execute

Code:

source /etc/bashrc
Hope this helps.....
Cheers !!!


thx reply,

But if I don't to change anything in system , I only use it to test , I will use it for one time only , can advise is there other method ? thx

catkin 11-02-2009 05:03 AM

Quote:

Originally Posted by elainelaw (Post 3740869)
I use the below command on the shell can set the variable , it works .

$export ORA=/opt/ora
echo $ORA
/opt/ora

$export JAVAHOME=/usr/java
echo $JAVAHOME
/usr/java

but if I add these two lines to a file , and then run it , it do not work .

can advise I have many varibles that want to be added to my current login , except run it one by one , what can i do ? thx

Source the file rather than run it. When you run it it does work -- for the process the script is running in and any of its children; when that process ends the changes are lost; you want to make the change in your current shell; when you source the script its commands are run in your current shell exactly as if you typed them.


All times are GMT -5. The time now is 09:24 PM.