Subshell Question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Subshell Question
# 1  
Old 03-08-2005
Subshell Question

The profile of the user is empty. Then before I run the script I want I run a parameter file that populates the variables for oracle.

ORACLE_HOME
ORACLE_BASE
ORACLE_SID
PATH

etc ...


But it seems that these variables are not making it to the shell I am in because when I do an echo on these variable I get nothing.

We are in the korn shell and the parameter file is a special file .myvars.


Does anyone know why I am not getting the variable values for the program I run after this parameter file gets run. I am exporting the variables in the .myvars file???
# 2  
Old 03-08-2005
Code:
#!/bin/ksh
echo "ORACLE_HOME->[${ORACLE_HOME}]"
. .myvars
echo "ORACLE_HOME->[${ORACLE_HOME}]"

# 3  
Old 03-08-2005
Here it is

/mydir>#!/bin/ksh
/mydir>echo $ORACLE_HOME

/mydir>./.myvars
/mydir>echo $ORACLE_HOME



I get nothing before or after?

.myvars contents (I changed the dir names for this post)

#!/bin/ksh
ORACLE_HOME=/oracle_home
export ORACLE_HOME
ORACLE_BASE=/oracle_Base
export ORACLE_BASE
ORACLE_SID=MYDB
export $ORACLE_SID
ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export ORA_NLS33
PATH=.:/usr/bin:/usr/sbin:/etc:$ORACLE_HOME/bin:/bin:/opt/bin:/usr/ccs/bin
export PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:/usr/openwin/lib:/usr/dt/lib
export LD_LIBRARY_PATH
export LOADER_HOME=$ORACLE_HOME/bin
TNS_ADMIN=$ORACLE_HOME/network/admin
export TNS_ADMIN
# 4  
Old 03-08-2005
You can simply include that myvars file which contains varialble information as,

. ./myvars

For Example,

/tmp/myvars contains
test="hai gm"
test1="bye"

#!/bin/ksh
. /tmp/myvars

echo $test
echo $test1

Try this. did you get that?
# 5  
Old 03-08-2005
pay attention to my original posting AND to the way '.myvars' were called!
Code:
#!/bin/ksh
echo "ORACLE_HOME->[${ORACLE_HOME}]"
. .myvars
echo "ORACLE_HOME->[${ORACLE_HOME}]"

# 6  
Old 03-08-2005
use echo $$
to see whether the script is running in the parent shell or child shell.

If run the script in the parent shell ... you can retain the env variables
you are exporting in the script.

. ./x.sh makes x.sh to run in the parent shell.

Code:
$ unset a
$ 
$ ./x.sh
20344
$ echo $$
53178
$ . ./x.sh
53178
$ cat x.sh
export a="hello world "
echo $$
$

# 7  
Old 03-08-2005
Sometimes it's hard to see the forrest for the trees.

Just to clarify:
Code:
. ./myvars

Notice the space after the first period, "."? This causes the envornment variables set in myvars to stick so to speak.

Thomas
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How will these subshell commands behave?

Hello, I am firing off some scripts from a main script, cd B/ ./EV_B_m0-m200_hex1.sh & ./EV_B_m0-m200_hex2.sh & wait ...more It would be useful to put a bit of time between the two to clean up the output to the terminal. I think this would work, cd B/ ... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

2. Shell Programming and Scripting

Getopts in the subshell of ksh

Hi, the getopts doesnt seem to be working in the subshell of the ksh. when I echo $@ and $* from the subshell it shows nothing. even when I am capturing the parameters from the outer shell and passing while invoking the file then I am still not getting it properly. the below code is in the... (9 Replies)
Discussion started by: hitmansilentass
9 Replies

3. Shell Programming and Scripting

While loop subshell problem

People, Here is my code while read ln do xyz=$(echo $ln/$val1*100-100|bc -l|xargs printf "%1.0f\n") if && ; then iam="YELLOW" fi done <<< "$(grep "^" $TMPOUT)" where $TMPOUT is a flat file which contains a set of values. Whilst executing the above, I get an error... (4 Replies)
Discussion started by: sathyaonnuix
4 Replies

4. Shell Programming and Scripting

Basename in subshell

Hi All, I would like to improve my bash scripting skill and found a problem which I do not understand. Task is to search and print files in directory (and subdirecories) which contains its own name. Files can have spaces in name. This one works fine for files in main directory, but not for... (4 Replies)
Discussion started by: new_item
4 Replies

5. Shell Programming and Scripting

While loop subshell problem

Hi, I have the below script while true; do read -p "Please enter schema password: " -s -e pswd1 echo read -p "Please retype schema password: " -s -e pswd2 echo && { echo -e "password mismatch.\n"; continue; } validateOraclePassword $pswd1... (2 Replies)
Discussion started by: varu0612
2 Replies

6. Shell Programming and Scripting

getopts in a subshell

Hello, I've a little problem with one of my ksh scripts and I manage to narrow it to the script here: #!/bin/ksh writeLog() { paramHandle="unknown" OPTIND=1 while getopts :i: option $* do case $option in i) paramHandle=${OPTARG} ;; esac done echo... (2 Replies)
Discussion started by: Dahu
2 Replies

7. Shell Programming and Scripting

Killing a subshell

I am calling a script from with another script and reading its output one line at a time (using <childscript> | while read line) in the parent script. If the output exceeds a predefined number of lines I want to kill the child shell from within the parent shell. I decided to print the process ID... (2 Replies)
Discussion started by: slash_blog
2 Replies

8. Shell Programming and Scripting

Passing arguments to the subshell

I have a shell script which is invoked by passing an argument. The outer shell script calls another subshell and I want the argument passed down to flow down to the subshell. E.g Invoking a shell ======>> abc_refresh.ksh NM Below is the content of abc_refresh.ksh Value1=$1... (7 Replies)
Discussion started by: Mihirjani
7 Replies

9. Shell Programming and Scripting

passing of a varibale to subshell

Hi All, I need some info. Could you please tell me how to use the variable of a parent shell in the subshell. Also can we modify the variable in the subshell ? If yes, will the modified variable visible in the parent shell I am using two prg. a.sh #!/usr/bin/ksh temp_var="abhishek"... (3 Replies)
Discussion started by: AbhishekG
3 Replies

10. Shell Programming and Scripting

Start subshell with different STDOUT

Hello Before I get to my question let me explain the situation. I am writing a ksh script to startup several instances of an application. That is done by executing another ksh script (let's call it startApp) with some arguments. Now, startApp writes some information to stdout that I don't want... (3 Replies)
Discussion started by: EvilBoz
3 Replies
Login or Register to Ask a Question