LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-23-2005, 02:12 PM   #1
Yig
Member
 
Registered: Aug 2005
Location: Montreal, Qc
Distribution: CentOs 4.5/5.0
Posts: 113

Rep: Reputation: 15
Best way to define variables?


I need to define some variables.

I put the following at the end of /etc/profile:

export JAVA_HOME=/usr/java/jdk1.5.0_04
export ANT_HOME=/apache-ant-1.6.5
export PATH=${PATH}:${ANT_HOME}/bin
export PATH=${PATH}:${JAVA_HOME}/bin

Is there a better way to do this or is this the standard accepted way?

Thanks!
 
Old 08-23-2005, 03:31 PM   #2
PenguinPwrdBox
Member
 
Registered: Oct 2003
Posts: 568

Rep: Reputation: 31
No. That works, but it will be done globally, which you may or may not want.
If you want it local only (current user) - then append it to ~/.bash_profile (if you use bash, of course.)

The correct, or accepted way to do this, is to first declare the variable, and then export it to make it available to the system.

JAVA_HOME=/usr/java/jdk1.5.0_04
ANT_HOME=/apache-ant-1.6.5
PATH=${PATH}:${ANT_HOME}/bin
PATH=${PATH}:${JAVA_HOME}/bin

export $JAVA_HOME
export $ANT_HOME
export $PATH

The way you do it works, but this is cleaner - because technically, you shouldn't declare and export all in the same go. It should be a two step process.
 
Old 08-23-2005, 03:58 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I think it depends on your distribution and other factors, such as if several people use the machine and may use a shell other then Bash or the Csh. /etc/profile is generally where the system wide login script would be located. I believe that it would run when a person logs in who uses either the bash or csh as their default login shell. I don't know about the korn shell or tsh.
Even if a particular shell doesn't use /etc/profile, I'm betting that whatever login script file it uses, will source the /etc/profile file if it exists.
One example, for SuSE, you would make the changes to /etc/profile.local and not to /etc/profile itself. Your best bet may be to to become familiar with your system and distro, and make the changes where they are expected. Things usually work out the best when you work with the system.

One alternative may be to move the settings to the linuxrc script (might be a linuxrc.local on your system). This will make the setting a part of the boot process however this may be unnecessary overkill for you particular example.
 
Old 08-24-2005, 05:09 PM   #4
Yig
Member
 
Registered: Aug 2005
Location: Montreal, Qc
Distribution: CentOs 4.5/5.0
Posts: 113

Original Poster
Rep: Reputation: 15
I modified profile to declare and export my variables in 2 steps. Works fine.

This server will be mostly used for remote application (CVS, DB2, Tomcat, etc..) so giving those variables to everybody is ok.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
define jhon Linux - Networking 2 08-30-2004 07:42 PM
how to define variables in the c file of kernel riquelme Programming 2 05-16-2004 07:42 PM
question on #define h/w Programming 7 12-03-2003 05:14 PM
using #define Jo_Nak Programming 4 06-11-2003 01:46 PM
Shel scripting: variables pointing to variables and case Dark_Helmet Programming 5 06-08-2003 11:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration