• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting Enviroment variables inside a shell

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
This is a stupid question and maybe a bit too easy....
I have installed Linux RedHat 7.1 workstation recently on my system. In Windows NT, we can write a .cmd file, set some environment variables, and execute that file on the dos prompt so that the environment of the current window is set. For example, the following are the contents of wlstart.cmd file:
set PATH=c:\jdk1.3\bin;c:\weblogic\bin;%PATH%
set CLASSPATH=;%CLASSPATH%
set CLASSPATH=c:\student;%CLASSPATH%
set CLASSPATH=c:\weblogic\classes\boot;%CLASSPATH%
set CLASSPATH=c:\weblogic\eval\cloudscape\lib\cloudscape.jar;%CLASSPATH%
set WEBLOGICCLASSPATH=c:\weblogic\classes
set WEBLOGICCLASSPATH=c:\weblogic\license;%WEBLOGICCLASSPATH%
set WEBLOGICCLASSPATH=c:\weblogic\lib\weblogicaux.jar;%WEBLOGICCLASSPATH%
set WEBLOGICCLASSPATH=c:\weblogic\myserver\serverclasses;%WEBLOGICCLASSPATH%
java -cp %classpath% -Dweblogic.class.path=%WEBLOGICCLASSPATH% -Dweblogic.system.home=c:\weblogic -Dweblogic.home=c:\weblogic -Djava.security.policy==c:\weblogic\weblogic.policy weblogic.Server
Now, my question is, how to achieve a similar thing in Linux. I know it is done thru' shell scripts. I wrote a script and ran it using
bash first.sh
command
The script is written below:
#! /bin/bash
ORION_HOME=/home/sanjeev
export ORION_HOME
when i checked the environment variable ORION_HOME using "set" command, I did not see the variable set.
I have tried to read thru' books but no clue.....
Please help me...
I have tried to log in as Super User also, but even that does not work.
Please help....
****Another twist to the situation***********************
..if I add the command "set" as the last line of the above script, like:
#! /bin/bash
ORION_HOME=/home/sanjeev
export ORION_HOME
set
Then it shows that for the period of execution of the shell, the ORION_HOME IS SET. Once the shell scripts exits, the environment does not reflect this???
Regards
Sanjeev
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the difficulty you are having is that when you invoke your script using 'bash first.sh' your current shell is spawning a sub-shell (which is essentially a copy of your current shell, environment etc) in which to run this script. When your script has completed, that sub-shell has also completed (type 'man exec' for more info on this kind of behaviour) and exits, returning the control to the shell on which you invoked your command. Your script 'first.sh' set the environment variable in the sub-shell not your current shell so when the script exited the changes you had made in the execution of the script to the environment were lost.
If you want to retain the changes made during the execution of the script in your current shell/environment, you must run it in your current shell. Type:
. first.sh
when you then run 'set' you should see changes.
 
Sanjeev Verma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx a ton Nigel. I can't tell ya what a help you have been!!!
Regards
Sanjeev
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
Even I have the same problem. Can you pl mention how exactly to execute in the same environment? If i have a file name aa.sh can you give the command to execute it?
Is it #sh .aa.sh
Please Reply,
Rohit

Originally posted by Sanjeev Verma:
Hi all,
This is a stupid question and maybe a bit too easy....
I have installed Linux RedHat 7.1 workstation recently on my system. In Windows NT, we can write a .cmd file, set some environment variables, and execute that file on the dos prompt so that the environment of the current window is set. For example, the following are the contents of wlstart.cmd file:
set PATH=c:\jdk1.3\bin;c:\weblogic\bin;%PATH%
set CLASSPATH=;%CLASSPATH%
set CLASSPATH=c:\student;%CLASSPATH%
set CLASSPATH=c:\weblogic\classes\boot;%CLASSPATH%
set CLASSPATH=c:\weblogic\eval\cloudscape\lib\cloudscape.jar;%CLASSPATH%
set WEBLOGICCLASSPATH=c:\weblogic\classes
set WEBLOGICCLASSPATH=c:\weblogic\license;%WEBLOGICCLASSPATH%
set WEBLOGICCLASSPATH=c:\weblogic\lib\weblogicaux.jar;%WEBLOGICCLASSPATH%
set WEBLOGICCLASSPATH=c:\weblogic\myserver\serverclasses;%WEBLOGICCLASSPATH%
java -cp %classpath% -Dweblogic.class.path=%WEBLOGICCLASSPATH% -Dweblogic.system.home=c:\weblogic -Dweblogic.home=c:\weblogic -Djava.security.policy==c:\weblogic\weblogic.policy weblogic.Server
Now, my question is, how to achieve a similar thing in Linux. I know it is done thru' shell scripts. I wrote a script and ran it using
bash first.sh
command
The script is written below:
#! /bin/bash
ORION_HOME=/home/sanjeev
export ORION_HOME
when i checked the environment variable ORION_HOME using "set" command, I did not see the variable set.
I have tried to read thru' books but no clue.....
Please help me...
I have tried to log in as Super User also, but even that does not work.
Please help....
****Another twist to the situation***********************
..if I add the command "set" as the last line of the above script, like:
#! /bin/bash
ORION_HOME=/home/sanjeev
export ORION_HOME
set
Then it shows that for the period of execution of the shell, the ORION_HOME IS SET. Once the shell scripts exits, the environment does not reflect this???
Regards
Sanjeev


 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nigel has already answered this: you use a "period" or "full stop" character as the command to execute the script:
. aa.sh
Got it?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry if I misunderstand you but how could you run aa.sh with a "full stop". I mean when I type : .aa.sh there is always an error message like this :
bash: .simple_test.sh: command not found
Then I tried : ./simple_test.sh. The script file can run now however it did not affect the enviroment variable list.
Please reply me. Thank you very much.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is dot_blank_scriptName.
dot_scriptName is interpreted as a filename, starting with a dot.

If this is too suspicious to you, you could use the more conservative way:
.

And
P.S.: I don't like nonesense bulk-quoting. Nobody likes.

(edited, because tags I used didn't work as expected. realised know)
[ July 19, 2004: Message edited by: Stefan Wagner ]
[ July 19, 2004: Message edited by: Stefan Wagner ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic