Setting up variables


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Setting up variables
# 1  
Old 03-27-2008
Setting up variables

Hi all,

I have a shell script that sets up the environment for an application running on UNIX - ksh. This script is run using:

. ./script_name XX

where XX is a parameter. I want to run it from another shell script but when I do it I don't get the envornment variables set up and the prompt doesn't change to what it changes when I run it manually. Can you please tell me what am I doing wrong?

#!/bin/ksh
cd /applications/scripts
. ./script_name XX

I know that the script is running coz in the middle of the execution I'm asked for a second parameter that is required for the script_name script.

Thanks in advance!
# 2  
Old 03-27-2008
does your embedded script actually export its variable?

Since you're trying to source the embedded script, you'd want to share the environment variables (ie, export my_var='foobar'). You'll need to export the embedded script's variable(s) in order for them to show in the environment for the parent script.
# 3  
Old 03-28-2008
Hi Curleb,

Thanks for replying. I think I found out what was happening. I read somehwere else that a script is called from another script a new shell is opened and the variables are set up for that second shell (or child shell) and once the script is executed the shell is closed and with it all the variables. So if I want to execute the script in the current shell I have to use the option . ./script_name.sh (with the dot and space) and at Exit 0 the previous shell disappears and the child shell stays as current. This is my intepretation of what I read, I'm sure there is more professional explanation for it Smilie

Thanks for your help
# 4  
Old 03-28-2008
I'm not sure the "exit 0" part is correct. When a child exits, you lose its state. Then you're back in the parent. When the parent exits, nothing is left.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Setting variables in UNIX

Hi, I am a beginner in Unix. Now I am learning setting up variables. However, I am receiving an error. Can anyone please help me with it My command as Test=unixprogramming returns the error command not found. (I am using FreeBSD Unix and in my terminal, it is ~% instead of $ . is the... (2 Replies)
Discussion started by: kgopan
2 Replies

2. UNIX for Dummies Questions & Answers

Setting up environment variables

Hi all, This is my first post here. I need to set up a few environment variables with a shell script. Some are hard-coded, but some should come from other commands or as input from the user. How do I do that? For example, I need to export a variable as such: export DISPLAY=127.0.0.1:8.0 ... (2 Replies)
Discussion started by: exchequer598
2 Replies

3. UNIX for Dummies Questions & Answers

Setting Environment Variables

#!/bin/bash if ; then ASS1_DATA_DIR=./ echo $ASS1_DATA_DIR export ASS1_DATA_DIR echo "data dir" fi if ; then ASS1_OUTPUT_DIR=./ export ASS1_OUTPUT_DIR fi I want to create a new environment variable ASS1_DATA_DIR and ASS1_OUTPUT_DIR in bash and set them to the current... (4 Replies)
Discussion started by: bigubosu
4 Replies

4. UNIX for Dummies Questions & Answers

Need help with setting up environment variables

hi all, I would appreciate if some one could explain me the difference between setting up the variables as shown below HOME=${HOME:-"/home/user1"} HOME=/home/user1 (1 Reply)
Discussion started by: SSSB
1 Replies

5. UNIX for Dummies Questions & Answers

setting enviroment variables help

Hello everyone, I am currently trying to program in java in unix platform for the first time, so far it is OK as long as I use class libraries which come with java distribution. Unfortunately when I try to use external libraries I have to use -classpath option which I rather not doing all the... (1 Reply)
Discussion started by: run123
1 Replies

6. UNIX for Advanced & Expert Users

setting some variables

i have a file .NAMEexport MY_NAME=JOE when i do this at the command prompt #. .NAME $echo MY_NAME $JOEi created a script called Run.sh . .NAME At the command prompt i did #sh Run.sh #echo $MY_NAMEit returns nothing. What have i missed out? (7 Replies)
Discussion started by: new2ss
7 Replies

7. Shell Programming and Scripting

Setting up Environment Variables

Hi all, I am trying to set up some variables in a shell script. The variables contain values of various paths needed to run a java module. The problem is the variables dont seem to be setting at all. here is what i am trying to do : JAR_HOME=/home/was5/bdcms/scheduledjobs/lib export... (6 Replies)
Discussion started by: rpandey
6 Replies

8. AIX

Setting Variables not working

Hi all, I am trying to set up some variables in a shell script. The variables contain values of various paths needed to run a java module. The problem is the variables dont seem to be setting at all. here is what i am trying to do : JAR_HOME=/home/was5/bdcms/scheduledjobs/lib export... (1 Reply)
Discussion started by: rpandey
1 Replies

9. Shell Programming and Scripting

cat setting variables

hi All I have a file that has 4 lines: 1. yesterday's date (mm/dd/yyyy) 2. yesterday's day- dd 3. yesterday's month- mm 4. yesterday's year- yyyy I want to read this file and place them in variables. how can I do this. Please help. thanks in advance!! KS (3 Replies)
Discussion started by: skotapal
3 Replies

10. UNIX for Dummies Questions & Answers

setting environment variables ???

Hello, I want to set some environment variables with this script: ip=$@ echo Remote Computer: $ip PERLDB_OPTS="CallKomodo=$ip:9000 RemotePort=$ip:9010 PrintRet=0" export PERLDB_OPTS PERL5LIB=/opt/komodo export PERL5LIB echo PERLDB_OPTS: $PERLDB_OPTS echo PERL5LIB: $PERL5LIB But it... (5 Replies)
Discussion started by: Gargamel
5 Replies
Login or Register to Ask a Question