It is currently Mon, 08 Aug 2022 19:38:45 GMT



 
Author Message
 global shell variables
a couple of hopefully simple questions:

I'm writing a set of shell scripts to do various things, and I want the
main one to call a script at the top which will set various preference
values:

-----------
#! /bin/sh
# main script

.prefs           # load in prefs file

echo web server = $webServer    # $webServer set in .prefs

-----------

-----------
#! /bin/sh
# prefs file

webServer= http://www.**-**.com/     #initialise variable
-----------

The variable is set within the prefs file but seems to have local scope
ie. I cannot use it in the main file (it does not get displayed by the
echo statement). Is there a way to make the variables declared in .prefs
have global scope?



 Mon, 02 Jul 2001 03:00:00 GMT   
 global shell variables
[...]

You should call the .prefs script as follows:

. .prefs

this will execute the script .prefs within the same shell environment of
the caller script  and not in a new shell, so the variables set in .prefs
will be set in the main script as well.

*fabio*



 Mon, 02 Jul 2001 03:00:00 GMT   
 global shell variables

The "prefs" file is _included_ here, not called. BTW, you forgot a space
between . and prefs.

You should remove this line, since the file is included in the mail file.

--
    Thomas

Volleyball: http://www.stud.fernuni-hagen.de/q5100380



 Mon, 02 Jul 2001 03:00:00 GMT   
 
   [ 5 post ] 

Similar Threads

1. file contents into variable, or global variable from shell script

2. global shell environment variable

3. global variables in shell

4. EXPORTING global variables...

5. global env. variables for tcsh

6. accessing a global variable

7. initialize the global variables in .so files

8. Unaligned access (bus error) on Solaris on global variable

9. Regarding locks and global variables

10. defining global environment variable


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software