f



How tosource sh script/setup file from tcl script?

I have a tcl script that generates sh command file that looks like this:
setenv var1 value1
setenv var2 value2
etc.

i would like to source so all the variables will be set to the terminal window.

any idea's?

i've tried >exec source my_command_file

but it seems that tcl has "source" command as well and its not working...

Thanks,
G
0
Guy
7/31/2014 11:22:19 AM
comp.lang.tcl 23429 articles. 2 followers. Post Follow

3 Replies
393 Views

Similar Articles

[PageSpeed] 37

On Thursday, July 31, 2014 1:22:19 PM UTC+2, Guy wrote:
> I have a tcl script that generates sh command file that looks like this:
>=20
> setenv var1 value1
> setenv var2 value2
>=20
> i would like to source so all the variables will be set to the terminal w=
indow.

Note that the above syntax is rather that of the "other" shell family: csh,=
 not sh.

  SH-Family:   var1=3Dvalue1
 =20
  CSH-Family:  setenv var1 value1

Anyway, whatever the shell, the principle to keep in mind is that no child =
process (like a tclsh) will touch your environment. The only thing a child =
can do is spit out some text like the above to stdout, and then your shell =
will "swallow" that text and eval them as shell commands.=20

It can do so either directly with 'eval' (both csh and sh):

     eval `child-spitting-out-text`

or indirectly through a file with 'source' (csh) or '.' (sh):

     child-spitting-out-text > mytmp
     source mytmp ;# CSH case
     . mytmp      ;# SH case

A typical shell-spitting tool will likely have a command-line switch to cho=
ose for which family to generate output:=20

     child-spitting-out-text -sh
     child-spitting-out-text -csh

Lastly, note that the sh idiom 'var1=3Dvalue1' does set an internal shell v=
ariable, but does not automatically "export" it to the environment of later=
 children of the shell. It may or not matter to you, depending on the way t=
hose vars are used thereafter. Anyway, to force the export, either issue th=
e command "set -a" once before issuing the "." command, or make sure that t=
he lines look like

     var1=3Dvalue1 ; export var1

or (for modern shells like Bash, but not for true old Bourne shell)

     export var1=3Dvalue1

Bottom line: as you can see, Tcl's [source] does not play any role in all t=
his. Again, the Tcl child's only job is to output the text.

HTH,

-Alex
0
Alexandre
7/31/2014 5:35:32 PM
On Thursday, July 31, 2014 8:35:32 PM UTC+3, Alexandre Ferrieux wrote:
> On Thursday, July 31, 2014 1:22:19 PM UTC+2, Guy wrote:
>=20
> > I have a tcl script that generates sh command file that looks like this=
:
>=20
> >=20
>=20
> > setenv var1 value1
>=20
> > setenv var2 value2
>=20
> >=20
>=20
> > i would like to source so all the variables will be set to the terminal=
 window.
>=20
>=20
>=20
> Note that the above syntax is rather that of the "other" shell family: cs=
h, not sh.
>=20
>=20
>=20
>   SH-Family:   var1=3Dvalue1
>=20
>  =20
>=20
>   CSH-Family:  setenv var1 value1
>=20
>=20
>=20
> Anyway, whatever the shell, the principle to keep in mind is that no chil=
d process (like a tclsh) will touch your environment. The only thing a chil=
d can do is spit out some text like the above to stdout, and then your shel=
l will "swallow" that text and eval them as shell commands.=20
>=20
>=20
>=20
> It can do so either directly with 'eval' (both csh and sh):
>=20
>=20
>=20
>      eval `child-spitting-out-text`
>=20
>=20
>=20
> or indirectly through a file with 'source' (csh) or '.' (sh):
>=20
>=20
>=20
>      child-spitting-out-text > mytmp
>=20
>      source mytmp ;# CSH case
>=20
>      . mytmp      ;# SH case
>=20
>=20
>=20
> A typical shell-spitting tool will likely have a command-line switch to c=
hoose for which family to generate output:=20
>=20
>=20
>=20
>      child-spitting-out-text -sh
>=20
>      child-spitting-out-text -csh
>=20
>=20
>=20
> Lastly, note that the sh idiom 'var1=3Dvalue1' does set an internal shell=
 variable, but does not automatically "export" it to the environment of lat=
er children of the shell. It may or not matter to you, depending on the way=
 those vars are used thereafter. Anyway, to force the export, either issue =
the command "set -a" once before issuing the "." command, or make sure that=
 the lines look like
>=20
>=20
>=20
>      var1=3Dvalue1 ; export var1
>=20
>=20
>=20
> or (for modern shells like Bash, but not for true old Bourne shell)
>=20
>=20
>=20
>      export var1=3Dvalue1
>=20
>=20
>=20
> Bottom line: as you can see, Tcl's [source] does not play any role in all=
 this. Again, the Tcl child's only job is to output the text.
>=20
>=20
>=20
> HTH,
>=20
>=20
>=20
> -Alex

Thanks Alex.

i think i didnt understand exactly what to do.

lets say that my tcl script generates a file called "my_csh_command" that l=
ooks like this:
setenv aaa val_a
setenv bbb val_b

i can modify the tcl script so it will export:
puts "setenv aaa val_a"
puts "setenv bbb val_b"

i would like that when my tcl script is done these variables will be set in=
 the terminal (which is tcsh).


Thanks,
G

0
Guy
8/5/2014 11:38:05 AM
On Tuesday, August 5, 2014 1:38:05 PM UTC+2, Guy wrote:
> 
> lets say that my tcl script generates a file called "my_csh_command" that looks like this:
> 
> setenv aaa val_a
> setenv bbb val_b
> 
> i would like that when my tcl script is done these variables will be set in the terminal (which is tcsh).

Again, there is no way for a child process (the tclsh running your script) to affect the parent's (the shell) environment. You must end up doing:
 
    tclsh foo.tcl > my_csh_command
    source my_csh_command

for the shell's environment to be properly updated.
But you can use a shell alias to automate the two lines above:

    alias update_my_env "tclsh foo.tcl > my_csh_command;source my_csh_command"

-Alex
0
Alexandre
8/5/2014 12:58:07 PM
Reply:

Similar Artilces:

Dose there any tcl script to translate an file with embedded tcl
Hi I need to generate some big file, but there are rules for generate these files Ex . ============================== Start input a [0] wire input a [1] wire .. .. .. .. input a [1000] wire End ================================= Dose there any tcl script can help to translate a file with embedded tcl script into a new file For example this is a source file ======================== Start * set i 0 * for { set i 0 } { $i < 1000 } { incr i } { * puts input a [$i] wire * } End ========================== After Translate ======================= Start input a [0] wire input a [1] wire .. .. ...

Does anyone have a Tcl Script which does a Multi Part File Upload to web site ( TCL CGI )
Hello all, I am after a Tcl script which I can use on my apache Linux server which a user can upload files or pictures to the site with ... Any help is appreciated, Thank you for the help, Sean - HeliHobby.com Sean wrote: > Hello all, > > I am after a Tcl script which I can use on my apache Linux server > which a user can upload files or pictures to the site with ... > > Any help is appreciated, > > Thank you for the help, > > Sean - HeliHobby.com I use ncgi for ths (from tcllib). It rocks! high quality code that never fails. For instance the file upload...

Tcl command to evaluate a tcl script?
Hi all, I need to evaluate a separate tcl file within a tcl file. Is there any tcl command to evaluate a tcl file ? Regards, Prabu.K prabu wrote: > Hi all, > > I need to evaluate a separate tcl file within a tcl file. Is there any > tcl command to evaluate a tcl file ? > > Regards, > Prabu.K > hi, try: source your_other_tcl_file.tcl cheers, Tobi ...

Script to convert Tcl scripts to Python?
Hi, I have a 10k+ line Tcl program that I would like to auto convert over to Python. Do any scripts exist that can convert ~90% of the standard Tcl syntax over to Python? I know Python doesn't handle strings, but just for general syntax e.g., puts > print, expr > math operations thanks On Apr 23, 9:17 am, "Achillez" <n...@na.com> wrote: > Hi, > > I have a 10k+ line Tcl program that I would like to auto convert over to > Python. Do any scripts exist that can convert ~90% of the standard Tcl > syntax over to Python? I know Python doesn't hand...

Run Matlab Script within TCL Script
Hello TCL Experts, I am new to the world of TCL/TK. So, pardon me if you think my question is very basic. I have an .m file which I need to run within my tcl script. Ideally, I would like to run the tcl script on machines where there is no MATLAB installed. Do you think there is a way to do it? If yes, can you please direct me to do the same/ Sanket jainsanket1@gmail.com wrote: > Hello TCL Experts, > > I am new to the world of TCL/TK. So, pardon me if you think my > question is very basic. > Basic questions are welcome. However, your description is confusing: > I hav...

How will I execute an expect script from a tcl script?
I have tried to execute an expect script from a tcl script. But I am unable to do that. I have used following options: one is exec {expect myexpect.exp} another one is source myexpect.exp only "expect myexpect.exp" is running properly. But while trying execute in both ways from tcl script the tcl script is not responding. Please help me to solve this problem. On Jun 7, 7:05 am, manasi.bis...@gmail.com wrote: > I have tried to execute an expect script from a tcl script. But I am > unable to do that. > > I have used following options: > one is > exec {expect my...

Tcl command to evaluate a tcl script? #2
Hi all, I need to evaluate a separate tcl file within a tcl file. Is there any tcl command to evaluate a tcl file ? Regards, Prabu.K prabu wrote: > I need to evaluate a separate tcl file within a tcl file. Is there any > tcl command to evaluate a tcl file ? You're probably looking for the "source" command. Other commands of interest would be "package require" or "eval". The command "load" is for binary shared libraries. -- Darren New / San Diego, CA, USA (PST) Scruffitarianism - Where T-shirt, jeans, and a three-day beard...

tcl script not working when called from cgi script
Why does this executable tcl file work when launched from a terminal window but not when called from a cgi script? notice the PITA space in the filename. ######################### contents of test.tcl: ######################## #! /bin/sh # the next line restarts using tclsh \ exec tclsh "$0" ${1+"$@"} set cmd "/bin/cp" set my_arg_1 "/data/log/2009/April/04-22-2009\ Data.txt" set my_arg_2 "/tmp/data.txt" set runcmd [list exec $cmd $my_arg_1 $my_arg_2] if {[catch $runcmd res]} { error "Failed to run command $runcmd: $res" } puts ...

executing a script file from a script file
Hi, as my code is getting bigger I'd like to partition it to make it better to read. What I'd like to do is to outsource parts of it in seperate m-files. As a huge amount of variables is used and produced it is really impractical to use functions for it because I always need to specify the input und output variables. Is there a way to do what I want in matlab? Just like an equivalent to the "\input" command in Latex. Gerrit Gerrit Hofbauer <gerrit.hofbauer@gmx.de> wrote in message <h420qv$14km$1@ariadne.rz.tu-clausthal.de>... > Hi, > > as my c...

end-of-file in Tcl script?
In perl, an __END__ or __DATA__ causes the interpreter stop processing the script. And I'm used to putting all kinds of notes after the __END__ --without having to make them into comments. I understand that Tcl stops processing a script if it encounters a control-z ( \u001a ) character, but I can't figure out how to insert one via a text editor. Every way I've tried gets an "Invalid command name" error. So, is there any way to emulate perl's __END__ in Tcl? ~greg In article <2b5af3d2-f5ee-4d3f-a50f-76210202de26@i12g2000prf.googlegroups.com>, Jeff Hobbs ...

tcl script to upload files
I am searching for a script in tcl that i cam use to upload files on a server. Please if any one has sth to say or give me, contact at : nemesis345crew@gmail.com. Your help will be great! ThankX!!!!! http://wiki.tcl.tk/15002 http://tcllib.sourceforge.net/doc/ftp.html HTH, Robert ...

upload ".zip" file [transfer files using tcl script]
I want to upload .zip file from my windows box to unix box i mean i want to transfer files using tcl script. Thanks in advance file transfer protocol - ftp - is the protocol of choice. A wiki page "Simple ftp uploader" shows an example using the ftp package. May I suggest to access the wiki page per http://taipu.de/ida.htm, to get pointed to the wiki page http://wiki.tcl.tk/1502 with minimal typing effort? best regards, Roland Frank senthilvaishnavi schrieb: > I want to upload .zip file from my windows box to unix box i mean i > want to transfer files using...

Script Script
Ever want to try a little script to see if it will work but don't want to go through the hassle of creating a file with #!/bin/bash at the top and making it executable and running it as ./script-name and then deleting it or moving it? You can use the fc command in bash, but it runs in the current shell, which can cause real problems, and once you've done it, if it is more than one line, or you do anything else in between at the prompt, it's gone. fc also echos the script, which is really ugly and confusing. So I wrote this little script which has been tremendously u...

Scripting in Tcl?
Hello, I just got a pretty weird idea, but one that could be interesting from an academic point of view. Is there any scripting engine in pure Tcl, one that would allow me to convert something like this (metalanguage now, not Tcl): for i 0 .. 9 { putvar i } into 1: set i 0 2: putvar i 3: if i <= 9 goto 1 So that I can evaluate one command at a time, ie allow doing only 20 commands at a time. I'm considering writing a small strategic game that will allow scripting the objects, so that the players may write code for buildings/crafts and the game will be held on the game se...

Web resources about - How tosource sh script/setup file from tcl script? - comp.lang.tcl

Partners - beSUCCESS ENGLISH
Media Partners: Based in Singapore, e27 is a media company focused on growing Asia’s technology startup ecosystem. It reports on tech startup ...

Ford Customline
Aussie originals - this much-revered big sedan produced a unique local variant

Bibliography, 1928-1952, Raymond Bernard Cattel, R. B. Cattell, Raymond Cattell
Cattell, R. B. (1928). The significance of theactual resistances in psycho-galvanic experiments. British Journal of Psychology,19, 34-43. Cattell, ...

1960 Plymouth Savoy Restoration Story
1960 Plymouth Savoy Restoration Story

The Ampeg B-15 : From Inception To Resurrection
Bass Player magazine is your source for acoustic and electric bass guitar tabs, chords and free online bass guitar lessons, tutorials and videos ...

Partners
Media : US based VentureBeat is a media company obsessed with covering amazing technology and why it matters in our lives. From the most innovative ...

Ejacs: a JavaScript interpreter for Emacs
... fundamental, you don't want to have to build it. Problem #5: No polymorphic toString One of the great strengths of JavaScript is the toSource ...

Arctic Cold Cuts Fuel Supplies as Refineries to Pipelines Freeze
Record cold weather pummeled energy infrastructure across the U.S., prompting gas pipeline operators to reduce flows, fuel terminals to shut ...

The "e-Annoyance" law
... to read stuff like this. But... Let'slook at the law as it already existed, and apply the new changes andsee what it looks like. (Links tosources ...

The Autocrat's Algorithm
Is Google News helping to spread propaganda?

Resources last updated: 1/26/2016 4:11:04 PM