Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > There is no such thing as a stupid question

There is no such thing as a stupid question
Thread Tools
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jan 9, 2003, 05:25 PM
 
Until you get a load of this one:

Say I have a bash script named DBENV that basically sets some environment variables. What is the difference between executing

> . DBENV

or

> ./DBENV


note: in the first command, there is a space between the period and the script name.

I ask, because I'm messing (learning) with Oracle9i and the first one works fine while the second causes problems i.e. SQLPLUS cannot find a dynamic library.

Thanks!
(Last edited by DaGuy; Jan 10, 2003 at 02:50 AM. )
     
Senior User
Join Date: Sep 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 10, 2003, 08:14 AM
 
the first one basically says to
'source' the script in the current
shell.

The second one says 'create a new child shell
and execute the script in that and oh,
by the way, the script is located in
the curent directory', and return to
thhe current shell when the child is done.

Doesn't suprise me at all
that the 2nd one doesn't work quite
right
     
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Jan 10, 2003, 10:12 AM
 
You're right, that WAS dumb!
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jan 10, 2003, 10:29 AM
 
You were dying to use that icon, weren't you.




Howardm4's answer the mechanics of the commands. Thanks very much for that.

Alas, It's a bit confusing since I don't see why executing in the current shell versus the forked one produces different results. The forked one would have the same commands.

Is it the case, that the child process has additional (or different) runtime constraints not faced by the parent one i.e., permissions etc.

I'm not one bit clear on how variable scope is being handled or for that matter when to use
". scriptname" versus "./scriptname". I have always executed scripts with as "./scriptname" and never had hit an obstacle -until this point. Then again, I wasn't playing with major league app like Oracle9i.

Any help appreciated.

Thanks!

(Last edited by DaGuy; Jan 10, 2003 at 10:45 AM. )
     
Senior User
Join Date: Sep 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 10, 2003, 10:51 AM
 
what happens is that bash calls the
'execve' system call in the
current shell and the new child
shell is intialized w/ the environment
as stated by environ(7) (ie. do a
man environ).

If you have some oddball dynamic library
and the DYLD_LIBRARY_PATH variable set
in the current shell (do a 'env'),
it won't get passed to the child.
     
Senior User
Join Date: Apr 2000
Location: Woodridge, IL
Status: Offline
Reply With Quote
Jan 10, 2003, 10:59 AM
 
Well *I* learned something here so I'm happy.

However, don't kid yourself - there are stupid questions, as anyone who works in the business world knows.
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jan 10, 2003, 12:42 PM
 
Thanks, I see what's going on.



But what's the motivation for not passing identical enviroment vars to the child process?

Naively speaking, it seems safer to execute shells scripts as ". scriptname" then "./scriptname" since you risk loosing environment information in the former.

Wadda you think?

Thanks again for the discussion -hope it continues.


     
Senior User
Join Date: Sep 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 10, 2003, 01:33 PM
 
how does your current environment find
this special dynamic library? what do you
set?
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jan 10, 2003, 04:28 PM
 
Below are contents of the actual script. It doesn't appear to contain anything out of the ordinary.

What's giving me the headache is understanding the motivation, which then would justify when to use ". scriptname" as opposed to "./scriptname".

---------------------------------------


# Required for the database application.
export CLASSPATH=$S/DBCreate/oradev/classes/orapts.jar:$CLASSPATH
# Required for JDBC connection
export CLASSPATH=$S/jdbc/lib/classes12.zip:$CLASSPATH


echo ORACLE_SID: $ORACLE_SID
echo ORACLE_HOME: $ORACLE_HOME
echo SRCHOME: $SRCHOME
echo PATH: $PATH
echo DYLD_LIBRARY_PATH: $DYLD_LIBRARY_PATH
echo CLASSPATH: $CLASSPATH

echo Done Setting parameters


---------------------------------------

In case it helps:

DYLD_LIBRARY_PATH=/Users/oracle/9iR2/orahome/lib:/Users/oracle/9iR2/orahome/rdbms/

Thanks!
     
Senior User
Join Date: Sep 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 10, 2003, 05:51 PM
 
So all you want to do is use this
script file to set a few variables
and prevent you from having to type
all that junk over and over so that
you be in a shell, then run this
script (which you want to modify
the shell you're in) and then do
whatever?

Unix doesn't work like that.

Parent processes fork (create)
children processes. The children
do their work and then quit and
control is returned to the parent.

The child CANNOT affect the parent
in that way. That is the entire
reason for the '. script' syntax.
That syntax says 'pretend that I just
typed this stuff in, here and now'.

The other way (./script) does teh
whole child creation thing. So even
if the child inherited everything from
the parent, it wouldn't change zippo
in your case.

Of course, you could put that stuff in
your .profile or whatever so that all
shells read it upon startup.
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jan 10, 2003, 10:10 PM
 
I see... This makes me look at things a bit differently going forward. UNIX always keeps me on my toes.

Thanks, for clarifying matters. I appreciate it.

     
   
Thread Tools
Forum Links
Forum 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:01 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2