Mailinglist Archive: opensuse (4446 mails)

< Previous Next >
Re: [opensuse] VEEERY elementary script question
  • From: Jorge Fábregas <jfabregas@xxxxxxxxxxxxx>
  • Date: Tue, 5 Dec 2006 20:11:22 -0400
  • Message-id: <200612052011.22741.jfabregas@xxxxxxxxxxxxx>
On Tuesday 05 December 2006 8:01 pm, Greg Wallace wrote:
> After the script runs, I do an echo MYVAR and it comes up empty.  If I
> simply enter those same statements outside of a script it works fine!
>  Could someone enlighten me as to what the heck is wrong with having that
> in a script?

Ok, you need to "source" the script if you want all variables inside it within
your current shell. Try this (assuming your script is in current directory)

source ./yourScript.sh

and try now. You'll see that all variables you defined within script are now
part of your session. Another shortcut , instead of typing source, try this:

. ./yourScript.sh (that's period space & then your script)

The probem you are having is that, when you run your script a new shell is
created (the one that is going to actually run your script) and then after
the script ends, that shell dies and control resumes back to your shell.

Check this out:

http://mdobson.home.cern.ch/mdobson/onlinesw/unix-scripting.html#sec4sourceexecute

HTH,
Jorge
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups
References