LinuxQuestions.org
Review your favorite Linux distribution.
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 02-05-2013, 05:27 AM   #1
echipbk
LQ Newbie
 
Registered: Feb 2012
Posts: 13

Rep: Reputation: Disabled
2 cases of exporting Environment Variable


Run these commands on a terminal:
$ export x=hello
$ xterm & # this is xterm 1. "echo $x" we have hello
$ x=$x' add more here'
$ xterm & # this is xterm 2. "echo $x" we have "hello add more here"

So, it means I don't have to export the variable x a second time. The same holds for PATH env var. However, the following situation is different:

$ PS1="\T; \j jobs> "
$ xterm & # the bash prompt was the default (not change).

In this case, I have to export PS1 for it to work. In my opinion, I think PS1 is an environment variable, so it was exported already at start up. Thus, I don't have to export it a second time when I changed its value.

Can anyone help me to explain this? Thanks a bundle.

Last edited by echipbk; 02-05-2013 at 05:30 AM.
 
Old 02-05-2013, 05:30 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,929

Rep: Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306
I think when you execute xterm your PS1 will be set again (taken from ~/.bashrc).
 
1 members found this post helpful.
Old 02-05-2013, 05:00 PM   #3
echipbk
LQ Newbie
 
Registered: Feb 2012
Posts: 13

Original Poster
Rep: Reputation: Disabled
Thanks for your information. In addition, I have noticed people use this:

export PATH=$PATH:......

According to what I said, I think it's unnecessary to use 'export' there. We only need:
PATH=$PATH:.....

Is this correct? Am I missing something?
 
Old 02-06-2013, 12:38 AM   #4
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,929

Rep: Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306Reputation: 1306
More or less you are right. The problem is (in general) that [almost] noone knows if a given variable already exported, and reexporting will not cause any trouble.
 
  


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
Exporting a variable from within .xsession mike11 Linux - Newbie 2 03-31-2011 07:48 PM
exporting makefile variables to $(shell) environment ta0kira Programming 4 05-14-2010 12:45 AM
exporting variable in bash deathalele Programming 12 04-04-2009 01:24 PM
Problem with exporting environment variables in Fedora sugantha Linux - Newbie 11 05-26-2008 05:13 AM
exporting environment variables from a file? concoran Linux - Newbie 4 04-19-2008 05:49 PM


All times are GMT -5. The time now is 04:52 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration