Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
The variabls that export exports should be avilable to all
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Thu May 27, 2010 5:18 pm    Post subject: The variabls that export exports should be avilable to all Reply with quote

I export a variable TEST, and as soon as I kill the virtual terminal, it's gone! This should not happen right?

What is the expected behavior?

*Update --

So what does the export variable do? Reads variables from a file and applies it to a terminal?
_________________
My blog


Last edited by dE_logics on Thu May 27, 2010 5:57 pm; edited 1 time in total
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Thu May 27, 2010 5:33 pm    Post subject: Reply with quote

This is exactly expected behaviour. :P

export provides the variable to your current shell and to all the sub-shells. Once you exit from your current shell, the variable is lost. If you want some system level export, you will need to define your variables in /etc/env.d
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/


Last edited by ppurka on Thu May 27, 2010 5:35 pm; edited 1 time in total
Back to top
View user's profile Send private message
massimo
Veteran
Veteran


Joined: 22 Jun 2003
Posts: 1226

PostPosted: Thu May 27, 2010 5:33 pm    Post subject: Reply with quote

I would not expect anything else.
_________________
Hello 911? How are you?
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Thu May 27, 2010 5:47 pm    Post subject: Reply with quote

Quote:
This is exactly expected behaviour.


Yeah I was expecting that.

Actually I'm referring a book that was published in '97. So he's talking about bash 2.0
_________________
My blog
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Thu May 27, 2010 5:50 pm    Post subject: Reply with quote

Was the same back then too: export has always been only to children of the shell in which the variable was exported.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Thu May 27, 2010 5:58 pm    Post subject: Reply with quote

So what does the export variable do? Reads variables from a file and applies it to a terminal?
_________________
My blog
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Thu May 27, 2010 7:13 pm    Post subject: Reply with quote

The shell built-in export command just marks an existing environment variable for export, as in
Code:
export TEST
or else creates a new environment variable marked for export, as in
Code:
export TEST=foo
Variables not so marked are private to the current process. When a child process is created, for example when the shell executes an external command, only the environment variables marked for export are copied into that child process's environment.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Fri May 28, 2010 3:56 am    Post subject: Reply with quote

Ok, but what's the difference between foo=bar and export foo=bar?

The programs (other than the current running bash) will not be able to see the variable?
_________________
My blog
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri May 28, 2010 4:01 am    Post subject: Reply with quote

Correct. The third variant is
Code:
foo=bar
export foo
Then child programs will be able to see foo.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Fri May 28, 2010 5:18 am    Post subject: Reply with quote

Ok. I see.

So if I define a variable in /etc/profile, it will be only specific to the real terminals (not the virtual ones), similarly it will be only defined for the virtual terminals if I define it in .bashrc.

Thus I have to define the same variable in both .bashrc and /etc/profile to make it an environment variable? I mean this will be called an environment variable right, the proper method is /etc/env.d, but this method is also the right one?
_________________
My blog
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri May 28, 2010 5:29 am    Post subject: Reply with quote

No. Since your DE is started by a "real" terminal, it'll inherit everything exported in /etc/profile and in .~/.bashrc. But, don't define things by modifying /etc/profile unless you can't help it. Use the /etc/env.d/ mechanism instead.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Fri May 28, 2010 6:18 am    Post subject: Reply with quote

Hummm...I did not see this hapenning, anyway I'll experiment again.

Update --

Nope, this is not happening. I've set HISTCONTROL=ignoredups in /etc/profile but the duplicate history gets recorded in the virtual terminals. I have to set HISTCONTROL=ignoredups in .bashrc in order to get it working.
_________________
My blog
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Fri May 28, 2010 6:22 am    Post subject: Reply with quote

Notice, my DE starts using rc.

Also the export variable does not seem to work for all files.

For e.g. I made a file named test, which contained definition of a few variables, then I
Code:
export test
, but it says invalid identifier.
_________________
My blog
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9507
Location: beyond the rim

PostPosted: Fri May 28, 2010 9:38 am    Post subject: Reply with quote

export has absolutely nothing to do with files. It simply makes a single variable accessible to child processes of the current shell.
As for your issue with /etc/profile vs. .bashrc, start reading the "Invocation" section of the bash manpage, the whole stuff is a bit tricky to understand due to the different ways bash can be started. Has nothing to do with "real" vs. "virtual" terminals, except that they may start bash in different ways.
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Fri May 28, 2010 10:15 am    Post subject: Reply with quote

Ok, thanks.
_________________
My blog
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri May 28, 2010 1:01 pm    Post subject: Reply with quote

Good advice. "/etc/profile" is sourced by login shells. If you log out of your DE and log back in, you'll see the modified environment in X terminals.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Fri May 28, 2010 2:20 pm    Post subject: Reply with quote

But apparently that's not happening...
_________________
My blog
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri May 28, 2010 6:21 pm    Post subject: Reply with quote

Well, it's happening for me. One question and then a test. Are you defining the environment variables in /etc/env.d/ or by modifying /etc/profile directly? If the former, please make sure you've run env-update.

Now the test. Although this shouldn't be necessary, as a test, please reboot and then check for the existence of your exported variables. If this works then it means that you're not fully shutting down your DE. What is your DE, by the way? Also, what shell are you using?

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Sat May 29, 2010 6:20 am    Post subject: Reply with quote

in /etc/profile.

I'm using KDE with xterm and konsole.

I'm trying it out... again.
_________________
My blog
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Sat May 29, 2010 6:26 am    Post subject: Reply with quote

Nope, same issue it's not working.

May be I have to export /etc/profile manually from the login shells?
_________________
My blog
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Sat May 29, 2010 6:38 am    Post subject: Reply with quote

Look. Instead of messing around with /etc/profile, just create a file /etc/env.d/99myenv and dump all your variables in there. For example mine contains
Code:
EDITOR="/usr/bin/vim"
MANPAGER=/usr/bin/vimmanpager
LIBXCB_ALLOW_SLOPPY_LOCK=1
BROWSER=firox
PRELINK_PATH_MASK="/home:/root"
Then run env-update and reboot. That's it. This solution is independent of whichever shell you are using (for example zsh does not read /etc/profile).
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2253
Location: $TERM

PostPosted: Sat May 29, 2010 6:49 am    Post subject: Reply with quote

I would prefer modifying .bashrc and .bash_profile.

Anyway, this is not a problem, I'm trying to diagnose what's happening.
_________________
My blog
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Sat May 29, 2010 10:56 am    Post subject: Reply with quote

Please post your modified /etc/profile. The /etc/profile mechanism is demonstrably working because that's where your PATH comes from and you're not reporting that level of issue. My best guess now is some subtle problem with the way you're modifying it. :P

By the way, I asked this before but didn't see an answer. Are you using bash for your shell, or something more exotic? @ppurka has point out a nuance that I was reaching for but didn't fully understand: some other shells (e.g., zsh) apparently do not source /etc/profile but some other file.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
cwr
Veteran
Veteran


Joined: 17 Dec 2005
Posts: 1969

PostPosted: Sat May 29, 2010 11:51 am    Post subject: Reply with quote

It might be worth using a variable other than "test", as well, to avoid adding to
the confusion. /bin/test is a program, and I'm pretty sure "test" is a bash built-in.

Will
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Sat May 29, 2010 3:08 pm    Post subject: Reply with quote

Yes, but $test isn't.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum