You are not logged in.

#1 2007-11-05 21:48:56

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,911

sourcing from a bash script ?

In my Staden package certain environment settings need to be set before and after using the staden programs.

I've tried to do this from a bash script but could not get the settings to be used in the xterm the scripts are started from, so the user needs to source them manually with

. /etc/staden/staden-start and . /etc/staden/staden-stop  (see below for the content of the files)

Can someone guide me how to achieve this from a script ?


/etc/staden/staden-start

# emacs: -*- shell-script -*- mode
# Note this file is sourced into the user session

# save originals
SAVED_TCL_LIBRARY=$TCL_LIBRARY
SAVED_TK_LIBRARY=$TK_LIBRARY
SAVED_PATH=$PATH
test -n "$MANPATH" && export SAVED_MANPATH=$MANPATH
test -n "$LD_LIBRARY_PATH" && export SAVED_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"

export STADENROOT=/opt/staden

. ${STADENROOT}/staden.profile


echo "staden environment activated;"
echo "The staden environment is only valid in this terminal session;"
echo "use stadenstop or end session to deactivate the staden environment"

/etc/staden/staden-stop

# emacs: -*- shell-script -*- mode
# Note this file is sourced into the user session

export STADENROOT=
export STADENROOT_1_7=
export MACHINE=
export STADLIB=
export STADBIN=
export STADTABL=

# put back original variables, if non-empty
test -n "$SAVED_TCL_LIBRARY" && export TCL_LIBARY=$SAVED_TCL_LIBRARY && export SAVED_TCL_LIBRARY=
test -n "$SAVED_TK_LIBRARY" && export TK_LIBARY=$SAVED_TK_LIBRARY && export SAVED_TK_LIBRARY=
test -n "$SAVED_PATH" && export PATH=$SAVED_PATH && export SAVED_PATH=
test -n "$SAVED_MANPATH" && export MANPATH="$SAVED_MANPATH" && export SAVED_MANPATH=
if test -n "$SAVED_LD_LIBRARY_PATH"
then
    export LD_LIBRARY_PATH="$SAVED_LD_LIBRARY_PATH"
    export SAVED_LD_LIBRARY_PATH=
else
    export LD_LIBRARY_PATH=
fi

echo "staden environment deactivated."

Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#2 2007-11-05 22:00:56

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: sourcing from a bash script ?

if you want a script to set up those variables, they'll all need an 'export' - otherwise the variable values will not pass on to child processes.

Offline

#3 2007-11-05 23:08:50

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: sourcing from a bash script ?

And if you're just _running_ the script in xterm, there's no way to "up export" variables to the parent (Xterm in this case).

You can however source the script into Xterm though, do "source /script/wherever"

Jams

Offline

#4 2007-11-06 22:37:37

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,911

Re: sourcing from a bash script ?

iphitus wrote:

And if you're just _running_ the script in xterm, there's no way to "up export" variables to the parent (Xterm in this case).

That's the answer i was afraid of and it's consistent with my own findings.
Sourcing manually is the way it works now.

Could a system-wide alias solve this and where should i install them ?


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#5 2007-11-07 09:47:27

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: sourcing from a bash script ?

For system wide, /etc/profile.d/ -- everything in there gets sourced.

For your own user, source it in ~/.bashrc or whatever shell you use.

Jams

Offline

Board footer

Powered by FluxBB