Ubuntu etc/profile: environmental variable doesn't display content
Hi,
i am trying to declare an environmental variable in the /etc/profile' (as per the tutorial i'm following) but when i declare it and do an echo i get nothing. Here's what i've done so far.. inside /etc/profile: # /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi if [ "$PS1" ]; then if [ "$BASH" ]; then PS1='\u@\h:\w\$ ' if [ -f /etc/bash.bashrc ]; then . /etc/bash.bashrc fi else if [ "`id -u`" -eq 0 ]; then PS1='# ' else PS1='$ ' fi fi fi LINUXTEST=Scripting export LINUXTEST umask 022 ******************** I found it odd that there were no other variables declared inside the /etc/profile. anyway in the i did Code:
echo $LINUXTEST on a side note, i've also created a new user and i was wondering how do you switch between users via the shell? thanks! |
That is because they are typically declared in individual profile files in /etc/profile.d subdirectory, typically for specific software packages.
The /etc directory is usually used for system wide environemtn setup for ALL users. For individual users, environment variables are declared in individuals ~/.profile and ~/.bashrc files. Which if you look at actually source the /etc/profile so as to first get the system wide settings. for some specific software would create a file /etc/profile.d/{software}.sh and put that software settings in that file. More importantly LOG and document what changes you made to the system, so when 3 years later you re-install your system you know what changes you made on your old system! |
added env variable to ~/.profile still doesn't work
Quote:
i tried adding the environment variable to ~./profle and i'm still getting no output. i can't seem to figure out what i'm doing wrong...any thoughts?? thanks! |
Hi greenpool,
Try adding the environment variables into /etc/environment |
Quote:
For users who have bash in their /etc/passwd entry ... All user processes inherit variables exported in /etc/profile this way. This includes GUI processes because GUI logon begins with a bash logon so every GUI process is a child/descendant of the bash logon process. A process in that tree could unset such environment variables in which case its descendants would not have the unset environment variables. A possible gotcha is that terminals started in the GUI environment are not logon shells so will not have any environment variables set by changes in /etc/profile since logon (unless the interactive, non-logon bash initialisation file, usually ~/.bashrc, does source /etc/profile). |
Thanks for the info guys.
I shall play around and see if it works! |
Put it in ~/.bashrc and make sure to start a new shell before trying to 'echo'.
|
Quote:
|
So i managed to get my original question working but now i'm facing another dilemma :banghead:
i have 2 users test hnz PROBLEM 1 in test /etc/profile environment variable is defined as Code:
LINUXTEST=Scripting when i do a echo $LINUXTEST i get 'Scripting' in hnz /etc/profile environment variable is defined as Code:
LINUXTEST=String i'm confused as to how this is possible cos i thought i should be accessing the same profile file in /etc? PROBLEM 2 for user 'test': i tried setting LINUXTEST within the user scope, in the ~/.profile file to Code:
LINUXTEST=Edition any help is greatly appreciated! thanks! |
Quote:
The system-wide configuration directory is /etc so /etc/profile (and whatever it sources) is where system-wide settings are made. From the GNU Bash Reference Manual: "When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable" and "When an interactive shell that is not a login shell is started, Bash reads and executes commands from ~/.bashrc, if that file exists". It is common practice to set up /etc/profile to source ~/.bashrc so logon shells are configured the same way as interactive non-logon shells. Alternatively it can be left for individual users to set up their own ~/.bash_profile to source ~/.bashrc so it is under their control. Aliases cannot be exported so they must be set up in each shell they are required in, hence they are commonly defined in ~/.bashrc. This leads to the concept that ~/.bashrc is "for aliases". It would be truer to say that ~/.bashrc is a good choice for aliases. Functions can be exported so they can be defined and exported in the bash login shell startup files or defined in the bash non-logon interactive shell startup files. The bash login shell startup files are /etc/profile plus whatever it sources and the first one of ~/.bash_profile, ~/.bash_login and ~/.profile that exists plus whatever it sources. The bash non-logon interactive shell startup files are ~/.bashrc plus whatever it sources. |
You write as if each of the two users has their own /etc/profile; do you mean ~/.profile?
There's an : instead of a = in LINUXTEST:Edition |
Quote:
and yes it was meant be '=' not ':' |
Quote:
Please post the relevant parts of /etc/profile, /home/test/.profile and /home/hnz/.profile and tell us how you did your tests -- using virtual terminals (via Alt+F<n> or, from the GUI, Alt+Ctrl+F<n>) or terminal emulators from the GUI desktop. For these tests it is essential to know if you logged on or started a post-logon interactive shell (the logon could be when you logged on to the GUI desktop). Do .bash_profile or .bash_login files exist in /home/test/ or /home/hnz/ (if they do, their .profile file will not be used)? |
All times are GMT -5. The time now is 08:30 AM. |