LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-08-2004, 12:22 PM   #1
tnine9
Member
 
Registered: Jan 2003
Posts: 39

Rep: Reputation: 15
Sub shell environment variables


I have two shell scripts. catalina.sh and setEnvDev.sh. The script catalina.sh calls setEnvDev.sh, and it then needs to use the environment variable created by setEnvDev.sh. Since the setEnvDev.sh sript is executed in a subshell, all of the environment variables are lost when the child shell dies. Is there any way to get around this?

Thanks,
Todd

catalina.sh line 115 to 123 is what I am referring to
Code:
#!/bin/sh
# -----------------------------------------------------------------------------
# Start/Stop Script for the CATALINA Server
#
# Environment Variable Prequisites
#
#   CATALINA_HOME   May point at your Catalina "build" directory.
#
#   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions
#                   of a Catalina installation.  If not present, resolves to
#                   the same directory that CATALINA_HOME points to.
#
#   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
#                   "stop", or "run" command is executed.
#
#   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
#                   the JVM should use (java.io.tmpdir).  Defaults to
#                   $CATALINA_BASE/temp.
#
#   JAVA_HOME       Must point at your Java Development Kit installation.
#
#   JAVA_OPTS       (Optional) Java runtime options used when the "start",
#                   "stop", or "run" command is executed.
#
#   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"
#                   command is executed. The default is "dt_socket".
#
#   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
#                   command is executed. The default is 8000.
#
#   JSSE_HOME       (Optional) May point at your Java Secure Sockets Extension
#                   (JSSE) installation, whose JAR files will be added to the
#                   system class path used to start Tomcat.
#
#   CATALINA_PID    (Optional) Path of the file which should contains the pid
#                   of catalina startup java process, when start (fork) is used
#
# $Id: catalina.sh,v 1.35 2003/05/08 08:19:58 jfclere Exp $
# -----------------------------------------------------------------------------

# OS specific support.  $var _must_ be set to either true or false.
cygwin=false
os400=false
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
esac

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '.*/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

# Get standard environment variables
PRGDIR=`dirname "$PRG"`
CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
if [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
  . "$CATALINA_HOME"/bin/setenv.sh
fi

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin; then
  [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  [ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"`
  [ -n "$CATALINA_BASE" ] && CATALINA_BASE=`cygpath --unix "$CATALINA_BASE"`
  [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  [ -n "$JSSE_HOME" ] && JSSE_HOME=`cygpath --path --unix "$JSSE_HOME"`
fi

# For OS400
if $os400; then
  # Set job priority to standard for interactive (interactive - 6) by using
  # the interactive priority - 6, the helper threads that respond to requests
  # will be running at the same priority as interactive jobs.
  COMMAND='chgjob job('$JOBNAME') runpty(6)'
  system $COMMAND

  # Enable multi threading
  export QIBM_MULTI_THREADED=Y
fi

# Get standard Java environment variables
if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
  BASEDIR="$CATALINA_HOME"
  . "$CATALINA_HOME"/bin/setclasspath.sh
else
  echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
  echo "This file is needed to run this program"
  exit 1
fi

# Add on extra jar files to CLASSPATH
if [ -n "$JSSE_HOME" ]; then
  CLASSPATH="$CLASSPATH":"$JSSE_HOME"/lib/jcert.jar:"$JSSE_HOME"/lib/jnet.jar:"$JSSE_HOME"/lib/jsse.jar
fi
CLASSPATH="$CLASSPATH":"$CATALINA_HOME"/bin/bootstrap.jar

if [ -z "$CATALINA_BASE" ] ; then
  CATALINA_BASE="$CATALINA_HOME"
fi

if [ -z "$CATALINA_TMPDIR" ] ; then
  # Define the java.io.tmpdir to use for Catalina
  CATALINA_TMPDIR="$CATALINA_BASE"/temp
fi

#Set the other shell script up here
export OTHER_LIBPATH="/home/ninet/ata/atatravel_v0301/atatravel/build/lib"
export DLSITEDIR="/home/ninet/ata/datalex231_v0301/datalex"

$DLSITEDIR/HostAccessServer/setEnvDev.sh
#echo "HAS_CLASSPATH=$HAS_CLASSPATH"

export CLASSPATH=$CLASSPATH:$BIC_CLASSPATH:$HAS_CLASSPATH:$OTHER_CLASSPATH
echo "Classpath  $CLASSPATH"


# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
  JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  CATALINA_HOME=`cygpath --path --windows "$CATALINA_HOME"`
  CATALINA_BASE=`cygpath --path --windows "$CATALINA_BASE"`
  CATALINA_TMPDIR=`cygpath --path --windows "$CATALINA_TMPDIR"`
  CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  JSSE_HOME=`cygpath --path --windows "$JSSE_HOME"`
fi

# ----- Execute The Requested Command -----------------------------------------

echo "Using CATALINA_BASE:   $CATALINA_BASE"
echo "Using CATALINA_HOME:   $CATALINA_HOME"
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
echo "Using JAVA_HOME:       $JAVA_HOME"

if [ "$1" = "jpda" ] ; then
  if [ -z "$JPDA_TRANSPORT" ]; then
    JPDA_TRANSPORT="dt_socket"
  fi
  if [ -z "$JPDA_ADDRESS" ]; then
    JPDA_ADDRESS="8000"
  fi
  if [ -z "$JPDA_OPTS" ]; then
    JPDA_OPTS="-Xdebug -Xrunjdwp:transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=n"
  fi
  CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS"
  shift
fi

if [ "$1" = "debug" ] ; then

  if $os400; then
    echo "Debug command not available on OS400"
    exit 1
  else
    shift
    if [ "$1" = "-security" ] ; then
      echo "Using Security Manager"
      shift
      exec "$_RUNJDB" $JAVA_OPTS $CATALINA_OPTS \
        -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
        -sourcepath "$CATALINA_HOME"/../../jakarta-tomcat-4.0/catalina/src/share \
        -Djava.security.manager \
        -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
        -Dcatalina.base="$CATALINA_BASE" \
        -Dcatalina.home="$CATALINA_HOME" \
        -Djava.io.tmpdir="$CATALINA_TMPDIR" \
        org.apache.catalina.startup.Bootstrap "$@" start
    else
      exec "$_RUNJDB" $JAVA_OPTS $CATALINA_OPTS \
        -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
        -sourcepath "$CATALINA_HOME"/../../jakarta-tomcat-4.0/catalina/src/share \
        -Dcatalina.base="$CATALINA_BASE" \
        -Dcatalina.home="$CATALINA_HOME" \
        -Djava.io.tmpdir="$CATALINA_TMPDIR" \
        org.apache.catalina.startup.Bootstrap "$@" start
    fi
  fi

elif [ "$1" = "embedded" ] ; then

  shift
  echo "Embedded Classpath: $CLASSPATH"
  exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
    -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
    -Dcatalina.base="$CATALINA_BASE" \
    -Dcatalina.home="$CATALINA_HOME" \
    -Djava.io.tmpdir="$CATALINA_TMPDIR" \
    org.apache.catalina.startup.Embedded "$@"

elif [ "$1" = "run" ]; then

  shift
  if [ "$1" = "-security" ] ; then
    echo "Using Security Manager"
    shift
    exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Djava.security.manager \
      -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start
  else
    exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start
  fi

elif [ "$1" = "start" ] ; then

  shift
  touch "$CATALINA_BASE"/logs/catalina.out
  if [ "$1" = "-security" ] ; then
    echo "Using Security Manager"
    shift
    "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Djava.security.manager \
      -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start \
      >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &

      if [ ! -z "$CATALINA_PID" ]; then
        echo $! > $CATALINA_PID
      fi      
  else
    "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start \
      >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &

      if [ ! -z "$CATALINA_PID" ]; then
        echo $! > $CATALINA_PID
      fi      
  fi

elif [ "$1" = "stop" ] ; then

  shift
  exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
    -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
    -Dcatalina.base="$CATALINA_BASE" \
    -Dcatalina.home="$CATALINA_HOME" \
    -Djava.io.tmpdir="$CATALINA_TMPDIR" \
    org.apache.catalina.startup.Bootstrap "$@" stop

else

  echo "Usage: catalina.sh ( commands ... )"
  echo "commands:"
  if $os400; then
    echo "  debug             Start Catalina in a debugger (not available on OS400)"
    echo "  debug -security   Debug Catalina with a security manager (not available on OS400)"
  else
    echo "  debug             Start Catalina in a debugger"
    echo "  debug -security   Debug Catalina with a security manager"
  fi
  echo "  embedded          Start Catalina in embedded mode"
  echo "  jpda start        Start Catalina under JPDA debugger"
  echo "  run               Start Catalina in the current window"
  echo "  run -security     Start in the current window with security manager"
  echo "  start             Start Catalina in a separate window"
  echo "  start -security   Start in a separate window with security manager"
  echo "  stop              Stop Catalina"
  exit 1

fi
setEnvDev.sh

Code:
#!/bin/sh
######################## (c) DATALEX PLC #########################
# 
# setEnv.bat
#
# Configures Environment options for the Datalex Booking Engine.
# Called by all scripts.
#
# Author: RK.
# $Lock$
# $Log: setEnv.datalex.sh,v $
# Revision 1.1.1.1  2002/04/29 21:32:23  a113027
#
#
# Revision 1.6  2001/08/02 10:43:28  maevel
# Added availopt.jar.
# Revision 1.5  2001/07/19 10:16:15  andrew
# changed to use classes12.zip oracle jdbc drive in classpath
# Revision 1.4  2001/05/21 08:41:19  ROBERTK
# new format. now includes environment variables for all services.
##################################################################

############## THE FOLLOWING PARAMETERS MUST BE SET  #############

############ HAS & Lookup parameters:
HOSTNAME=sun10
export HOSTNAME

#should be set by developer
#JAVA_HOME=/a01/Solaris_JDK_1.2.2
#On AIX use $JAVA_HOME/sh
JAVA_DIR=$JAVA_HOME/bin
export JAVA_DIR

#!!!!MAKE SURE YOU SET THIS!!
BIC_HOME=/home/ninet/ata/datalex231_v0301/datalex
HAS_HOME=$BIC_HOME/HostAccessServer
export BIC_HOME HAS_HOME

HAS_NAME=ataServ
JINI_GROUP=ataGrp
export HAS_NAME JINI_GROUP

ADMIN_EMAIL=todd.nine@iflyata.com
SMTP_MAIL=localhost
export ADMIN_EMAIL SMTP_MAIL

############ Database parameters:
DB_SERVER=sun9.ata.com
DB_NAME=dint
DB_LOGIN=dope_sa
DB_PASS=dope_sa

# DB_TYPE:mssql/oracle
DB_TYPE=oracle

export DB_SERVER DB_NAME DB_TYPE DB_LOGIN DB_PASS

##################################################################

############## common parameters #################################
############ PATHS:
HAS_LIBPATH=$HAS_HOME/lib
export HAS_LIBPATH

POLICYFILE=$HAS_HOME/policy.all
export POLICYFILE

PORT=8080
export PORT

############ OPTIONS:
# JAVA_OPTIONS:
#    Options that are passed to all java apps- web, lookup, startHAS, startIHS
#    eg: For JINI 1.1 on NT with 2*nic require:
#          -Dnet.jini.discovery.interface=ip_of_nic_to_webserver

JAVA_OPTIONS=-Djava.security.policy=$POLICYFILE
export JAVA_OPTIONS

# HAS_DEBUG: -D debug parameters
HAS_DEBUG="-Dcom.datalex.has.core.HostAccessServiceManager.verboseError=true -Dcom.datalex.has.core.HostAccessServiceManager.verboseError=true"

# HAS_FARES_OPTIONS:
# -DnumFares=10: max 10 private fares to be returned to frontend.
# -DmaxFareResponses=15: max 15 fares to be returned to frontend.
# -DfaresTimeout=45: 45secs allocated to fares database to obtain availability for requested fares.
# -DfareResponseArray=5,3,2,1: Display 5 of first pfare, 3 of second pfare,...
HAS_FARES_OPTIONS=""

#HAS_AVIS_OPTIONS:
#HAS_AVIS_OPTIONS="-DzipDirectory=/usr/jbookit/HostAccessServer/AvisData -Djava.protocol.handler.pkgs=com.sun.net.ssl.internal.www.protocol"
HAS_AVIS_OPTIONS=""

HAS_OPTIONS="-ms128mb -mx256mb -DhasGroup=$JINI_GROUP $HAS_DEBUG -Dbeanfactory.cfg=$HAS_HOME/HASbeanpolicies.cfg $HAS_FARES_OPTIONS $HAS_AVIS_OPTIONS"
export HAS_OPTIONS

# HAS_CLASSPATH:
HOSTS=$HAS_LIBPATH/nls_charset12.zip:$HAS_LIBPATH/travelservice.jar:$HAS_LIBPATH/galileoedi.jar:$HAS_LIBPATH/pars.jar:$HAS_LIBPATH/worldspan.jar:$HAS_LIBPATH/sabre.jar:$HAS_LIBPATH/amadeus.jar:$HAS_LIBPATH/amadeusv2api.jar:$HAS_LIBPATH/galileo.jar:$HAS_LIBPATH/bookitfares.jar:$HAS_LIBPATH/itinerary.jar:$HAS_LIBPATH/galileoedi.jar:$HAS_LIBPATH/pegasus.jar:$HAS_LIBPATH/avisxml.jar:$HAS_LIBPATH/gtmsxml.jar:$HAS_LIBPATH/availopt.jar:
JINI=$HAS_LIBPATH/jini-core.jar:$HAS_LIBPATH/jini-ext.jar:$HAS_LIBPATH/reggie-dl.jar:$HAS_LIBPATH/sun-util.jar:
DATABASE=$HAS_LIBPATH/tds.jar:$HAS_LIBPATH/classes12.zip:$HAS_LIBPATH/DEP.jar:$HAS_LIBPATH/mwi.jar:$HAS_LIBPATH/mwdas.jar:$HAS_LIBPATH/xml4j.jar:$HAS_LIBPATH/hasconfig.jar:$HAS_LIBPATH/HASConfigBean.jar:$HAS_LIBPATH/dasbeans.jar:$HAS_LIBPATH/hasstatistics.jar:$HAS_LIBPATH/dopeitineraries.jar:
HASCORE=$HAS_LIBPATH/hascore.jar:$HAS_LIBPATH/connectionframework.jar:$HAS_LIBPATH/hasconnectionservices.jar:
CONNECTIONS=$HAS_LIBPATH/hashttpconnectionserviceimpl.jar:$HAS_LIBPATH/hasedif1GTWconnectionserviceimpl.jar:$HAS_LIBPATH/hasmatipconnectionserviceimpl.jar:$HAS_LIBPATH/hasinnosysconnectionserviceimpl.jar:$HAS_LIBPATH/japi.jar:$HAS_LIBPATH/hasamadeusudpconnectionserviceimpl.jar:$HAS_LIBPATH/hasamadeusv2apiconnectionserviceimpl.jar:$HAS_LIBPATH/hasbookitfaresconnectionserviceimpl.jar:$HAS_LIBPATH/hasjcsapi.jar:$HAS_LIBPATH/httpsconnectionserviceimpl.jar:$HAS_LIBPATH/hasasciiudpconnectionserviceimpl.jar:
OTHERS=$HAS_LIBPATH/DUP.jar:$HAS_LIBPATH/mail.jar:$HAS_LIBPATH/activation.jar:$HAS_LIBPATH/jsapi.jar:$HAS_LIBPATH/jsse.jar:$HAS_LIBPATH/jcert.jar:$HAS_LIBPATH/jnet.jar:$HAS_LIBPATH/AvisCarDataBean.jar:$HAS_LIBPATH/castor-0.8.11.jar:$HAS_LIBPATH/xerces.jar:$HAS_LIBPATH/logging.jar:

HAS_CLASSPATH=$HOSTS$JINI$DATABASE$HASCORE$CONNECTIONS$OTHERS
export HAS_CLASSPATH
echo "$HAS_CLASSPATH"
 
Old 06-08-2004, 01:27 PM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
You could source it like the sample in your code above does:

if [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
. "$CATALINA_HOME"/bin/setenv.sh
fi

The '.' in the second line causes it to run in the same shell instead of a subshell.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
environment variables user_linux Linux - Newbie 3 06-15-2005 08:46 AM
Setting environment variables from shell script theta Linux - General 5 09-02-2004 08:50 PM
environment variables moeminhtun Linux - General 4 01-15-2003 09:50 AM
Environment variables kdnt Linux - Newbie 11 11-01-2002 08:19 AM
Environment Variables if you su concoran Linux - Newbie 1 08-16-2002 07:18 PM


All times are GMT -5. The time now is 04:12 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration