• 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 Linux Java environment

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest,

Thanks for your help. You were right; a space was required before the file name.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic