View previous topic :: View next topic |
Author |
Message |
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Thu May 27, 2010 5:18 pm Post subject: The variabls that export exports should be avilable to all |
|
|
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 |
|
|
ppurka Advocate
Joined: 26 Dec 2004 Posts: 3256
|
Posted: Thu May 27, 2010 5:33 pm Post subject: |
|
|
This is exactly expected behaviour.
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 |
|
|
massimo Veteran
Joined: 22 Jun 2003 Posts: 1226
|
Posted: Thu May 27, 2010 5:33 pm Post subject: |
|
|
I would not expect anything else. _________________ Hello 911? How are you? |
|
Back to top |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Thu May 27, 2010 5:47 pm Post subject: |
|
|
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu May 27, 2010 5:50 pm Post subject: |
|
|
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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Thu May 27, 2010 5:58 pm Post subject: |
|
|
So what does the export variable do? Reads variables from a file and applies it to a terminal? _________________ My blog |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu May 27, 2010 7:13 pm Post subject: |
|
|
The shell built-in export command just marks an existing environment variable for export, as in or else creates a new environment variable marked for export, as inVariables 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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Fri May 28, 2010 3:56 am Post subject: |
|
|
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Fri May 28, 2010 4:01 am Post subject: |
|
|
Correct. The third variant isThen 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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Fri May 28, 2010 5:18 am Post subject: |
|
|
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Fri May 28, 2010 5:29 am Post subject: |
|
|
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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Fri May 28, 2010 6:18 am Post subject: |
|
|
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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Fri May 28, 2010 6:22 am Post subject: |
|
|
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 , but it says invalid identifier. _________________ My blog |
|
Back to top |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9507 Location: beyond the rim
|
Posted: Fri May 28, 2010 9:38 am Post subject: |
|
|
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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Fri May 28, 2010 10:15 am Post subject: |
|
|
Ok, thanks. _________________ My blog |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Fri May 28, 2010 1:01 pm Post subject: |
|
|
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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Fri May 28, 2010 2:20 pm Post subject: |
|
|
But apparently that's not happening... _________________ My blog |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Fri May 28, 2010 6:21 pm Post subject: |
|
|
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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Sat May 29, 2010 6:20 am Post subject: |
|
|
in /etc/profile.
I'm using KDE with xterm and konsole.
I'm trying it out... again. _________________ My blog |
|
Back to top |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Sat May 29, 2010 6:26 am Post subject: |
|
|
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 |
|
|
ppurka Advocate
Joined: 26 Dec 2004 Posts: 3256
|
Posted: Sat May 29, 2010 6:38 am Post subject: |
|
|
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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Sat May 29, 2010 6:49 am Post subject: |
|
|
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Sat May 29, 2010 10:56 am Post subject: |
|
|
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.
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 |
|
|
cwr Veteran
Joined: 17 Dec 2005 Posts: 1969
|
Posted: Sat May 29, 2010 11:51 am Post subject: |
|
|
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Sat May 29, 2010 3:08 pm Post subject: |
|
|
Yes, but $test isn't.
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
|