It is currently Tue, 17 May 2022 02:18:34 GMT



 
Author Message
 how do I export a shell variable

I am using csh.  Suppose I have a script that sets a variable, then
finishes, for example in foo.mac below:

cat > foo.mac <<!
#! /bin/csh
set myvar=1    # or, setenv myvar 1
!

Now I have another script that calls foo.mac and want to know the value
of $myvar:

cat > bar.mac <<!
#! /bin/csh
foo.mac
echo $myvar
!

How do I get $myvar known to bar.mac?  I don't care if I need to use set
or setenv.

Thanks,
Greg
--
Gregory J. Sandell, Research Associate, sand...@sparky.parmly.luc.edu
Parmly Hearing Institute, Loyola University Chicago
6525 N. Sheridan Chicago IL 60626 USA voice:312-508-3976 FAX:312-508-2719
WWW: http://www.**-**.com/



 Tue, 01 Dec 1998 03:00:00 GMT   
 how do I export a shell variable

Gregory J. Sandell (sand...@sparky.parmly.luc.edu) wrote:
: I am using csh.  Suppose I have a script that sets a variable, then
: finishes, for example in foo.mac below:
: cat > foo.mac <<!
: #! /bin/csh
: set myvar=1    # or, setenv myvar 1
: !
: Now I have another script that calls foo.mac and want to know the value
: of $myvar:
: cat > bar.mac <<!
: #! /bin/csh
: foo.mac
: echo $myvar
: !
: How do I get $myvar known to bar.mac?  I don't care if I need to use set
: or setenv.

Uh, first of all, don't use csh for scripting. Just take my word for
it. There is still time for you not to end up as me.

# in the "top-level" script:
source foo.mac
source bar.mac
# script bar.mac knows myvar=1

--
-Brian
   ,---.     ,---.     ,---.     ,---.     ,---.     ,---.     ,---.  
  /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \  
.'  / \  `.'  / bsh20...@challenger.atc.fhda.edu `.'  / \  `.'  / \  `.
__,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.__



 Sat, 05 Dec 1998 03:00:00 GMT   
 how do I export a shell variable

In article <4q736d$...@tiptoe.fhda.edu> bsh20...@news.fhda.edu (Brian S Hiles) writes:

: Gregory J. Sandell (sand...@sparky.parmly.luc.edu) wrote:
: : I am using csh.  Suppose I have a script that sets a variable, then
: : finishes, for example in foo.mac below:
: : cat > foo.mac <<!
: : #! /bin/csh
: : set myvar=1    # or, setenv myvar 1
: : !
: : Now I have another script that calls foo.mac and want to know the value
: : of $myvar:
: : cat > bar.mac <<!
: : #! /bin/csh
: : foo.mac
: : echo $myvar
: : !
: : How do I get $myvar known to bar.mac?  I don't care if I need to use set
: : or setenv.
:
: Uh, first of all, don't use csh for scripting. Just take my word for

Fair enough.  But just in case you're stubborn, I believe that
csh's setenv exports variables automatically.

-fil



 Thu, 10 Dec 1998 03:00:00 GMT   
 how do I export a shell variable

: cat > foo.mac <<!
: #! /bin/csh
: set myvar=1    # or, setenv myvar 1
: !
: Now I have another script that calls foo.mac and want to know the value
: of $myvar:
: cat > bar.mac <<!
: #! /bin/csh
: foo.mac
: echo $myvar
: !
: How do I get $myvar known to bar.mac?

in bar.mac:
source foo.mac
echo $myvar

-Brian
--
   ,---.     ,---.     ,---.     ,---.     ,---.     ,---.     ,---.  
  /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \  
.'  / \  `.'  / bsh20...@challenger.atc.fhda.edu `.'  / \  `.'  / \  `.
__,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.__



 Fri, 11 Dec 1998 03:00:00 GMT   
 
   [ 4 post ] 

Similar Threads

1. export variables to calling shell in a shell-script

2. export variables to calling shell in a shell-script

3. Exporting Enviroment Variables in shell scripts

4. make - exporting shell variable to environment

5. exporting C shell variable

6. Adding/Changing an exported Shell Variable

7. problem with exporting a shell variable from a C Program

8. Export with variable variable-names?

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

10. Creating shell variable containing substring of another variable.


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