Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm quite new to Linux. Debian Wheezy is now running on my Laptop (64 bits).

I recently installed Oracle 11g R2 database for evaluation purpose, and defined environment variables (such as ORACLE_SID) through a script /etc/profile.d/oracle.sh. This works fine, but for the "oracle" user.

I change user by su - oracle.
The value of ORACLE_SID is different from the one specified in the /etc/profile.d/oracle.sh file. As the oracle user has no file (such as .bash_profile, .profile etc.) in its home directory, where can this value come from?

What is the overloading sequence of environment variables?

share|improve this question
    
yes, as debian user you have a hard time reading man pages with an invariant section. use google for man bash. you will find your answers there –  Bananguin May 18 '13 at 21:31
    
What's the login shell of the oracle user? Is there pam_env in the PAM configuration for su? Is there a ~oracle/.pam_environment file? –  Stephane Chazelas May 19 '13 at 21:14
add comment

migrated from meta.unix.stackexchange.com May 18 '13 at 21:16

This question came from our discussion, support, and feature requests site for users of Linux, FreeBSD and other Un*x-like operating systems..

1 Answer

up vote 4 down vote accepted

What ever set's the environment variable last wins. So it doesn't really matter, I would just set the variable in the oracle user's $HOME/.bashrc file towards the bottom.

The file $HOME/.bashrc is the key file which sources files such as /etc/bashrc and the files under /etc/profile.d/*.sh for example. So I would just set ORACLE_SID=whatever in $HOME/.bashrc.

Debugging Tip

If you want to see what's going on you can debug your login like so:

su - oracle -c "env SHELLOPTS=xtrace bash"

With the above command you can follow along as the different files are sourced by bash:

...
...
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/less.sh ']'
++ '[' '[\u@\h \W]\$ ' ']'
++ . /etc/profile.d/less.sh
+++ '[' -x /usr/bin/lesspipe.sh ']'
+++ export 'LESSOPEN=||/usr/bin/lesspipe.sh %s'
+++ LESSOPEN='||/usr/bin/lesspipe.sh %s'
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/PackageKit.sh ']'
++ '[' '[\u@\h \W]\$ ' ']'
++ . /etc/profile.d/PackageKit.sh
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/qt.sh ']'
++ '[' '[\u@\h \W]\$ ' ']'
++ . /etc/profile.d/qt.sh
+++ '[' -z /usr/lib64/qt-3.3 ']'
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/udisks-bash-completion.sh ']'
++ '[' '[\u@\h \W]\$ ' ']'
++ . /etc/profile.d/udisks-bash-completion.sh
+++ '[' -z '4.1.7(1)-release' ']'
+++ complete -o filenames -F __udisks udisks
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/vim.sh ']'
++ '[' '[\u@\h \W]\$ ' ']'
++ . /etc/profile.d/vim.sh
+++ '[' -n '4.1.7(1)-release' -o -n '' -o -n '' ']'
+++ '[' -x //usr/bin/id ']'
++++ //usr/bin/id -u
+++ '[' 0 -le 200 ']'
+++ return
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/which2.sh ']'
...
...
share|improve this answer
    
Yes, you are right, a /home/oracle/.profile file was executed when I switched user. This file has been created at install, and provided the latest value for ORACLE_SID variable. There was no mysterious origin for this value ! Thanks for your help ! –  user1185081 May 21 '13 at 19:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.