Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
which does nothing. although i was able to declare this within the shell and it printed the contents
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:
Originally Posted by A.Thyssen
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!
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!
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.
They could be written that way but it is not necessary; bash itself sources /etc/profile when the new shell is a login shell as described here.
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).
"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.
OK, so far so confusing, especially as you have edited your post since I asked about it.
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)?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.