Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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.
 
Saloon Keeper
Posts: 22678
153
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.
 
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic