[Swift-user] Question: Setting environment variables

Michael Wilde wilde at mcs.anl.gov
Fri May 28 13:21:24 CDT 2010


I dont know what your current script does, but in many or most cases, users use Swift to execute their *existing* application scripts, rather than re-writing the wrapper script in Swift.  You'd use Swift to run multiple invocations of your existing script in parallel.

For example, lets say you have an executable program "myprog". You might be running this from a shell script, say "run_myprog.sh" that sets up all the files and environment vars the programs expects.

In such cases, a common mode of using Swift is to define run_myprog.sh as the "application" in tc.data, and write a swift app function myprog() to call the run_myprog.sh wrapper.

Then, once you have a single invocation of the program working OK from Swift, you'd add a Swift "foreach" statement to run many invocations of the program in parallel.

So to answer your question more directly: you likely want to leave things like checking for the existence of environment variables to your shell script, and call your shell script from Swift.

- Mike

----- "Taleena R Sines" <trsines0 at frostburg.edu> wrote:

> The weird question about using the script to invoke them was in
> reference to if I'm checking, let's say, to see if an environmental
> variable exists:
> In the c-script:
> if(!$MY_ROOT)
> echo error
> 
> in the swift script, how would I check to see if this exists?
> 
> Taleena R. Sines
> Major: Computer Science
> 
> 
> 
> -----Original Message-----
> From: wilde at mcs.anl.gov [ mailto:wilde at mcs.anl.gov ]
> Sent: Fri 5/28/2010 1:55 PM
> To: Taleena R Sines
> Cc: Swift User
> Subject: Re: [Swift-user] Question: Setting environment variables
> 
> 
> ----- "Taleena R Sines" <trsines0 at frostburg.edu> wrote:
> 
> > The code I'm transforming has several environment variable sets, so
> > would I be adding every one to the data file?
> 
> You can specify multiple environment variables on a single application
> in tc.data like this:
> 
> localhost env /usr/bin/env none none
> ENV::VAR1="value1";ENV::VAR2="value2"
> 
> > After adding them to the file, would I need to do anything in the
> > actual script to invoke changes?
> 
> Environment variables are typically specified entirely in tc.data, so
> you don't need to do anything in your .swift script related to them
> (unless you need to change their value with each invocation of your
> program, which would require some coordination between your .swift
> script and a shell wrapper around your program to pass such values on
> the command line. But I suspect you are not doing that at this point.)
> 
> Regarding "invoke changes" - sounds like you might be thinking in
> terms of compiling or building, as in "cc" and "make". But Swift
> basically compiles, interprets, and executes your script from the
> .swift source code each time you run the swift command. So there is
> effectively nothing that needs to be done between changing your
> tc.data and .swift file, and then executing the swift command again to
> try your changes.
> 
> - Mike
> 
> >
> > Thank you, I'm sorry for the stream of questions
> 
> No problem, but please please please send them to swift-user :) so
> that more people can answer you and more can benefit from the answers.
> 
> > Taleena R. Sines
> > Major: Computer Science
> >
> >
> >
> > -----Original Message-----
> > From: Michael Wilde [ mailto:wilde at mcs.anl.gov ]
> > Sent: Fri 5/28/2010 1:04 PM
> > To: Taleena R Sines
> > Cc: Swift User
> > Subject: Re: [Swift-user] Question: Setting environment variables
> >
> > Did you make sure that all the fields are separated by a tab
> > character, not spaces?
> > If that was not the cause, I'll need to double-check and test my
> > syntax.
> >
> > (please send all your replies back to the swift-user list).
> >
> > - Mike
> >
> >
> > ----- "Taleena R Sines" <trsines0 at frostburg.edu> wrote:
> >
> > > I inserted that line and it is giving me the error:
> > > unexpected token: /
> > >
> > >
> > > Taleena R. Sines
> > > Major: Computer Science
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: Michael Wilde [ mailto:wilde at mcs.anl.gov ]
> > > Sent: Fri 5/28/2010 12:48 PM
> > > To: Taleena R Sines
> > > Cc: Swift User
> > > Subject: Re: [Swift-user] Question: Setting environment variables
> > >
> > > For:
> > >
> > > setenv CODE_HOME /trsines/code/my_code
> > >
> > > the example:
> > >
> > > localhost myapp /usr/bin/env none none ENV::myenvvar="something";
> > >
> > > would become:
> > >
> > > localhost myapp /usr/bin/env none none ENV::CODE_HOME
> > > ="/trsines/code/my_code";
> > >
> > > - Mike
> > >
> > > ----- "Taleena R Sines" <trsines0 at frostburg.edu> wrote:
> > >
> > > > If my code in c-script is :
> > > > setenv CODE_HOME /trsines/code/my_code
> > > >
> > > > What would actually be typed in the swift-script in place of
> that?
> > > > thank you
> > > >
> > > > T. R. Sines
> > > >
> > > >
> > > >
> > > >
> > > > -----Original Message-----
> > > > From: wilde at mcs.anl.gov [ mailto:wilde at mcs.anl.gov ]
> > > > Sent: Fri 5/28/2010 12:15 PM
> > > > To: Taleena R Sines
> > > > Cc: swift-user at ci.uchicago.edu
> > > > Subject: Re: [Swift-user] Question: Setting environment
> variables
> > > >
> > > > Taleena,
> > > >
> > > > You set env vars for a given app in the tc.data file using an
> "Env
> > > > profile":
> > > >
> > > >
> http://www.ci.uchicago.edu/swift/guides/userguide.php#profile.env
> > > >
> > > > For example:
> > > >
> > > > localhost myapp /usr/bin/env none none
> ENV::myenvvar="something";
> > > >
> > > > Thats not real clear in the User Guide - we will fix that.
> > > >
> > > > - Mike
> > > >
> > > >
> > > > ----- "Taleena R Sines" <trsines0 at frostburg.edu> wrote:
> > > >
> > > > > Hello,
> > > > > In swift, how would I set an environment variable?
> > > > > For example, in a c-script:
> > > > > setenv WKDIR /user/bin
> > > > >
> > > > > would translate to swift how?
> > > > > Thank you
> > > > >
> > > > > T. R. Sines
> > > > >
> > > > >
> > > > >
> > > > > _______________________________________________
> > > > > Swift-user mailing list
> > > > > Swift-user at ci.uchicago.edu
> > > > > http://mail.ci.uchicago.edu/mailman/listinfo/swift-user
> > > >
> > > > --
> > > > Michael Wilde
> > > > Computation Institute, University of Chicago
> > > > Mathematics and Computer Science Division
> > > > Argonne National Laboratory
> > >
> > > --
> > > Michael Wilde
> > > Computation Institute, University of Chicago
> > > Mathematics and Computer Science Division
> > > Argonne National Laboratory
> >
> > --
> > Michael Wilde
> > Computation Institute, University of Chicago
> > Mathematics and Computer Science Division
> > Argonne National Laboratory
> 
> --
> Michael Wilde
> Computation Institute, University of Chicago
> Mathematics and Computer Science Division
> Argonne National Laboratory

-- 
Michael Wilde
Computation Institute, University of Chicago
Mathematics and Computer Science Division
Argonne National Laboratory




More information about the Swift-user mailing list