LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-03-2003, 06:04 PM   #1
ashley75
Member
 
Registered: Aug 2003
Posts: 232

Rep: Reputation: 30
what is the difference between export and set


I have a basic question and I don't understand, what is the difference between SET, EXPORT, SETENV and you try to set your environment.

thanks
 
Old 11-03-2003, 06:13 PM   #2
djtoltz
Member
 
Registered: Nov 2003
Location: Eastern North Carolina, USA
Distribution: Mandrake
Posts: 51

Rep: Reputation: 20
Its pretty simple, if you understand that each invocation of the shell gets its own copy of the environment that was exported by it's parent, and commands (other than builtin shell commands) run in their own shell.

Therefore, if you say "set joe=fred", you've just set the value of joe in your current shell environment. If you then start another process, that process will get it's own environment and will inherit (get a copy of) only the variables that were exported to you and the ones you exported in the current shell. Therefore, the child process will not get the value of "joe", because you didn't export it. In some shells, you had to both "set" and "export" a variable to pass it on to your offspring. You can use just "export joe=fred" in bash as a shortcut.

I believe "setenv()" is only available to "C" programs and it works similarly to "set", but in "C", if you spawn another process, you have to specify how the environment will be passed to the child process. That is a more complex subject.

I hope this helps. I've pretty much managed to confuse myself. Maybe someone else can try to explain it. To simplify the situation, I'd advise you to use "export" whenever you are calling another script or application from your script. Usually, you want to carry your variables forward. If you are just writing a simple script that won't call any other scripts, you can just use "set".
 
Old 11-04-2003, 03:45 PM   #3
essential
LQ Newbie
 
Registered: Nov 2003
Location: Ljubljana, Slovenia
Distribution: Red Hat 9
Posts: 3

Rep: Reputation: 0
OK,. First of all let me say that I am a Linux newbie.

I tried the above mentioned export ENV_NAME=value, but it did not work as thought. I'm trying to add something to my PATH variable, but the result is that I have to set this variable up for each and every bash window I open. Can someone please explain to me what I am doing wrong? I do not seem to grasp what is going on.

A brief explanation of what I am doing:

# export|grep PATH
# export PATH=<what the above grep returned for PATH and add>:/usr/java/.....

Then javac works for one "session". In the next window I open I have to do this again. Very frustrating!

I gathered somewhere that I have to edit my .bashrc file, but do not know what to do with that file (~/.bashrc).

Oh, and I am using Red Hat 9.
 
Old 11-04-2003, 03:53 PM   #4
djtoltz
Member
 
Registered: Nov 2003
Location: Eastern North Carolina, USA
Distribution: Mandrake
Posts: 51

Rep: Reputation: 20
Ok, in order to understand what is happening, you need to realize that export only exports to the children of your shell ... not the parent. i.e. When you close your shell, you return to the parent environment and all that was set in your shell is lost with it.

To simplify what you are doing, you can reference your PATH variable as $PATH, so you can update your path with "export PATH=$PATH:/usr/java/...".

Finally, if you need to update your PATH permanently, you do need to edit your login profile. In Redhat, I think you'll find your PATH in ~/.bash_profile. It should look something like the following...

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

......... all you need to do is add your Java path to the "PATH=$PATH:$HOME/bin" line.
 
Old 11-04-2003, 04:13 PM   #5
essential
LQ Newbie
 
Registered: Nov 2003
Location: Ljubljana, Slovenia
Distribution: Red Hat 9
Posts: 3

Rep: Reputation: 0
First of all, thanks for the quick response. In spite of this my efforts where pointless. It still does not work. The line in my .bash_profile now looks like this:

PATH=$PATH:$HOME/bin:/usr/java/j2sdk1.4.1_05/bin

But after exiting the vi the env variable PATH was not altered at all. Even after I've opened another bash window. If I write this

export PATH=$PATH:/usr/java/j2sdk1.4.1_05/bin

it works like you suggested, only for the current window. What am I doing wrong?
 
Old 11-04-2003, 04:20 PM   #6
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
If you want it to exist for all of your windows, logout of every window or console.

The next time you login, PATH will be okay.
 
Old 11-04-2003, 04:21 PM   #7
djtoltz
Member
 
Registered: Nov 2003
Location: Eastern North Carolina, USA
Distribution: Mandrake
Posts: 51

Rep: Reputation: 20
I'm sorry I forgot to mention that you need to log completely out and log back in for your .bash_profile changes to take effect. That may mean exiting out of X-windows.
 
Old 11-04-2003, 04:30 PM   #8
essential
LQ Newbie
 
Registered: Nov 2003
Location: Ljubljana, Slovenia
Distribution: Red Hat 9
Posts: 3

Rep: Reputation: 0
You guys are great! It works fine now. Thanks a bunch!

Drinks are on me
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
TOS in IP Header set to Minimize-Dealay - no difference ddaas Linux - Networking 5 07-26-2005 07:32 PM
set/export command? blackzone Linux - Newbie 1 03-05-2005 07:11 PM
set and export using bash script acummings Linux - General 10 01-03-2005 02:22 PM
Permanently Set a Export Setting (LD_LIBRARY_PATH) nistelrooy Linux - General 1 11-25-2004 11:33 AM
When to use the set and when to use export command? davidas Linux - Newbie 5 03-29-2004 04:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:37 AM.

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