Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to selectively source a file for an interactive session.

Status
Not open for further replies.

Condore

Programmer
Aug 29, 2006
3
US
Hello all!

On my Solaris server, I currently have a menu in my .profile that gets executed when I log in. In this menu it asks a question and in response sources one of 3 files to set up environmental variables for my session.

I wanted to make a simple script that, when passed a parameter will source one of those 3 files which will set the environmental variables for my session and not just the script.

Here is what I have that works in the $HOME/.profile for my login:
Code:
        read AutoSys_ENV
        echo "You picked " $AutoSys_ENV

        if [ "$AutoSys_ENV" = "DEV" ]
        then
             echo "Entering Dev Environment"
           . /opt/autotree/autouser/autosys.ksh.dev.server1
         elif [ "$AutoSys_ENV" = "SIT" ]
        then
             echo "Entering Sit Environment"
           . /opt/autotree/autouser/autosys.ksh.sit.server1
         elif [ "$AutoSys_ENV" = "UAT" ]
        then
             echo "Entering Uat Environment"
           . /opt/autotree/autouser/autosys.ksh.uat.server1
         else
             echo "Invalid selection. "
         fi
I wanted to create a script called 'go' that can be passed the parameter "DEV", "SIT", or "UAT" that would source the appropriate "...autosys.ksh.XXX.server1" file which contains exported variables. Here is what I have so far:
Code:
#! /usr/bin/ksh
# script to change between environments
#
if [[ $# -eq 0 ]]; then
   echo "Give me dev, sit, or uat."
   exit
fi
if [[ $# -gt 1 ]]; then
   echo "What?"
   exit
fi
if [ $1 = "dev" ]; then
   . /opt/autotree/autouser/autosys.ksh.dev.server1
   echo $1 ; exit
fi

if [ $1 = "sit" ]; then
   . /opt/autotree/autouser/autosys.ksh.sit.server1
   echo $1 ; exit
fi
...etc

What I'm seeing is that the exported variables are not sticking around when the 'go' script ends. How do you source a file from within a script and keep the exported variables in your session which were set within the sourced file?

Thanks for any help or insight you all can provide!
 
You have to source the go script.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top