This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

setting Linux Java environment

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone help me with what is probably a ridiculously simple Fedora Linux
environment init problem. I admit that I am a Linux novice - I have always used Windows, but now need to quickly do some things with Java under Linux.

I have created a shell script and it works properly when I execute it from a Fedora Linux terminal window. I know that this is the case because I placed echo statements in the script and the echoed statements show that the enviroment variables (path, etc) have changed. However, once the script ends and I type echo $PATH in the terminal session window, the environment is the same as before I executed the script. The script is as follows:

#1/bin/sh

CLASSPATH=""
echo $CLASSPATH
export JAVA_HOME=/usr/java/jdk1.5.0_07
echo $JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
echo $PATH
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you execute it by typing its filename, it runs in its own copy of bash. That copy gets the new environment variables; then it exits, leaving the original shell's environment untouched. Instead of executing it, you want the current shell to simply evaluate its contents; you can do that with the dot (.) command: type ". filename", and the code in the file is executed by the current shell.
 
Manuel Comnenus
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest,

Could you provide an example? I am a little confused. This is what I am doing in the terminal window.

The script is in the current directory and it is named jinit, so I invoke it as with ...
./jinit
When I do this, I get the results that I reported.

I tried typing .jinit first. This doesn't work, so I am probably misinterpreting your instructions.

Thanks.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a space between the dot and "jinit":

. jinit
 
Manuel Comnenus
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest,

Thanks for your help. You were right; a space was required before the file name.
 
Bartender
Posts: 20924
127
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The dot is a shorthand for a command named "source". It's known as "sourcing" a script.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To do yourself a favor, it might be a good idea to set it in your permanent environment or in the system environment.

There are multiple ways to do it.

If you want to set the environment for every user of that machine, in former times you would have set the environment in /etc/profile .
I'm using ubuntu-linux where it is done in /etc/environment .

For a single user (yourself) you may set in ~/.bashrc and ~/.bash_login if your shell is bash.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!