- Environment variables settings through a script
- Posted by Pierre B. on January 23rd, 2004
I'm sorry to bother you if it is inappropriate to post my message here.
Is there a problem with Bash and environment variable settings through a
script?
Here's what's wrong.
I set a bunch of variables and (export them) during execution of a bash
script. I echo them all before exiting the script and they're all set. After
script execution (on return to the shell prompt), none of the variables are
set anymore.
Here's an excerpt of my dialogue
---------------------------------------------------------------------
[oracle@DB-server oracle]$ ./path
Executing...
declare -x COLORTERM=""
declare -x DISPLAY=":0.0"
declare -x GDMSESSION="KDE"
declare -x GS_LIB="/home/oracle/.kde/share/fonts"
declare -x
GTK_RC_FILES="/etc/gtk/gtkrc:/home/oracle/.gtkrc:/home/oracle/.gtkrc-kde"
declare -x G_BROKEN_FILENAMES="1"
declare -x HISTSIZE="1000"
declare -x HOME="/home/oracle"
declare -x HOSTNAME="DB-server"
declare -x INPUTRC="/etc/inputrc"
declare -x KDE_MULTIHEAD="false"
declare -x KONSOLE_DCOP="DCOPRef(konsole-2248,konsole)"
declare -x KONSOLE_DCOP_SESSION="DCOPRef(konsole-2248,session-3)"
declare -x LANG="en_US.UTF-8"
declare -x LD_ASSUME_KERNEL="2.4.1"
declare -x LESSOPEN="|/usr/bin/lesspipe.sh %s"
declare -x LOGNAME="oracle"
declare -x
LS_COLORS="no=00:fi=00:di=00;34:ln=00;36
i=40;33: so=00;35:bd=40;33;01:cd=40
;33;01
r=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cm d=00;32:*.exe=00;32:*.com=
00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00; 32:*.tar=00;31:*.tgz=00;31
:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:* .z=00;31:*.Z=00;31:*.gz=00
;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31: *.cpio=00;31:*.jpg=00;35:*
..gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*. png=00;35:*.tif=00;35:"
declare -x MAIL="/var/spool/mail/oracle"
declare -x OLDPWD
declare -x ORACLE_BASE="/usr/app/oracle"
declare -x ORACLE_DOC="/usr/doc/oracle/9.2.0.1"
declare -x ORACLE_HOME="/usr/app/oracle/9.2.0.1"
declare -x ORACLE_SID="TestDB"
declare -x
PATH="/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/oracle/bin:/usr/app/
oracle/9.2.0.1/bin,/usr/bin,/bin,/usr/bin/X11,/usr/local/bin"
declare -x PWD="/home/oracle"
declare -x SESSION_MANAGER="local/DB-server:/tmp/.ICE-unix/2013"
declare -x SHELL="/bin/bash"
declare -x SHLVL="4"
declare -x SSH_AGENT_PID="1933"
declare -x SSH_ASKPASS="/usr/libexec/openssh/gnome-ssh-askpass"
declare -x SSH_AUTH_SOCK="/tmp/ssh-XXwXg7w7/agent.1890"
declare -x TERM="xterm"
declare -x USER="oracle"
declare -x XAUTHORITY="/home/oracle/.Xauthority"
declare -x XMODIFIERS="@im=none"
Done!
[oracle@DB-server oracle]$ export
declare -x COLORTERM=""
declare -x DISPLAY=":0.0"
declare -x GDMSESSION="KDE"
declare -x GS_LIB="/home/oracle/.kde/share/fonts"
declare -x
GTK_RC_FILES="/etc/gtk/gtkrc:/home/oracle/.gtkrc:/home/oracle/.gtkrc-kde"
declare -x G_BROKEN_FILENAMES="1"
declare -x HISTSIZE="1000"
declare -x HOME="/home/oracle"
declare -x HOSTNAME="DB-server"
declare -x INPUTRC="/etc/inputrc"
declare -x KDE_MULTIHEAD="false"
declare -x KONSOLE_DCOP="DCOPRef(konsole-2248,konsole)"
declare -x KONSOLE_DCOP_SESSION="DCOPRef(konsole-2248,session-3)"
declare -x LANG="en_US.UTF-8"
declare -x LESSOPEN="|/usr/bin/lesspipe.sh %s"
declare -x LOGNAME="oracle"
declare -x
LS_COLORS="no=00:fi=00:di=00;34:ln=00;36
i=40;33: so=00;35:bd=40;33;01:cd=40
;33;01
r=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cm d=00;32:*.exe=00;32:*.com=
00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00; 32:*.tar=00;31:*.tgz=00;31
:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:* .z=00;31:*.Z=00;31:*.gz=00
;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31: *.cpio=00;31:*.jpg=00;35:*
..gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*. png=00;35:*.tif=00;35:"
declare -x MAIL="/var/spool/mail/oracle"
declare -x OLDPWD
declare -x
PATH="/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/oracle/bin"
declare -x PWD="/home/oracle"
declare -x SESSION_MANAGER="local/DB-server:/tmp/.ICE-unix/2013"
declare -x SHELL="/bin/bash"
declare -x SHLVL="3"
declare -x SSH_AGENT_PID="1933"
declare -x SSH_ASKPASS="/usr/libexec/openssh/gnome-ssh-askpass"
declare -x SSH_AUTH_SOCK="/tmp/ssh-XXwXg7w7/agent.1890"
declare -x TERM="xterm"
declare -x USER="oracle"
declare -x XAUTHORITY="/home/oracle/.Xauthority"
declare -x XMODIFIERS="@im=none"
[oracle@DB-server oracle]$
----------------------------------------------------------------------------
-------------------
(Yes, I'm trying to install Oracle...). Notice the ORACLE_<> variables set
during the script execution, that don't show up on the export command after
the script has executed.
I'm running this on a KDE on RH 9.
Am I wrong to expect this to work?
_____________________
Pierre Bergeron
- Posted by Andreas Janssen on January 23rd, 2004
Hello
Pierre B. (<c16031@hotpop.com>) wrote:
The Shell the script is run in knows the variables. However it is closed
when the script has been executed, and they aren't "inherited" to the
next higher level - the shell you are working in. To make it work, try
.. ./path
This should execute the script in the current shell. Alternativly, add
your variables to the file your shell calls when opened, like ~/.bashrc
or ~/.bash_profile, if you use bash.
best regards
Andreas Janssen
--
Andreas Janssen
andreas.janssen@bigfoot.com
PGP-Key-ID: 0xDC801674
Registered Linux User #267976
- Posted by Eric Moors on January 23rd, 2004
Pierre B. wrote:
this is the right place
this is a feature.
And it is not only zsh. AFAIK all shells do this similarly
it is not wrong. Unexpected (ie. for you) maybe
<SNIP>
Yes.
a script is executed in a subshell. It cannot alter its parent.
source it if you want it to run in the current shell.
.. ./path
(notice the leading dot) would alter the current shell.
Eric
- Posted by P.T. Breuer on January 23rd, 2004
Pierre B. <c16031@hotpop.com> wrote:
Of course they aren't. Why would they be? You executed the script in a
daughter shell, not in your current shell.
Go back to shell programming 101. Do not pass go.
Peter
- Posted by Jeroen Geilman on January 27th, 2004
P.T. Breuer wrote:
It's you again.
So typical, too:
- he starts off his post by apologising for any inconvenience
- he asks a simple question about the workings of a shell feature.
What do you do ?
You *BASH* him for not knowing the answer!
It'd be ironic if it wasn't so sad.
--
Jeroen Geilman
Analog bits courtesy of adaptr.
- Posted by P.T. Breuer on January 27th, 2004
Jeroen Geilman <jeroen-nospammat-adaptr.nl> wrote:
You may thank him on my behalf.
It's not a shell feature, it's a basic of programming, and shell
programming at that! You cannot affect the parent process by running
a subprocess - that's what to be a process _means_. Insulation.
Perhaps you are thinking of threads, which typically share certain
context with their parent?
I tell him to go back to computation 101, where they will explain to
him simple concepts that he is lacking.
No. I tell him that he is an ignoramus who ought not to be asking the
question he is asking, since it is based on a completely false premise.
One which the rest of the universe (which has taken computation 101)
does not hallucinate to along with him.
It'd be sad if it were not ironic!
Peter