Subject: Re: sourcing c-shell env - DN [1]
Paul Duffin <pduffin@mailserver.hursley.ibm.com> - 26 Nov 1999 - comp.lang.tcl
msubbu@my-deja.com wrote:
>
> Hi There,
> If I have a TCL script from which I want
> to call a C-shell script that sets up the
> environment variables for the subsequent
> TCL commands, how can this be done?
>
> Obviuosly I cannot exec that script, as it
> is a different process-space. And as the
> C-shell script may have conditionals, I cannot
> parse the c-shell script either.
>
> Is there any simple way of doing this?
>
I wrote the following proc to read the tclConfig.sh, it reads the file
line by line, throws away comments, converts assignments to set commands
and returns the result. You can easily modify this to process your
style of file. The caller simply evaluates the returned string to
set up the variables. You may want to set elements of the global env
array as that will affect the environment of any children.
This does not work well if special Tcl characters are in the file such
as {} etc.
proc ReadShellConfigFile {file} {
set comment {^[ \t]*#}
set re1 {^([_a-zA-Z][_a-zA-Z0-9]+)='([^']*)'$}
set sub1 {set \1 {\2}}
set re2 {^([_a-zA-Z][_a-zA-Z0-9]+)=(.*)$}
set sub2 {set \1 "\2"}
set contents {}
set hFile [open $file r]
while { [gets $hFile line] >= 0 } {
if { [regexp $comment $line] } {
continue
}
if { [regsub $re1 $line $sub1 line] } {
append contents $line \n
continue
}
if { [regsub $re2 $line $sub2 line] } {
append contents $line \n
continue
}
}
close $hFile
return $contents
}
--
Paul Duffin
DT/6000 Development Email: pduffin@hursley.ibm.com
IBM UK Laboratories Ltd., Hursley Park nr. Winchester
Internal: 7-246880 International: +44 1962-816880
Last modified
1999-12-10
1999-12-10
(195.108.246.50)
Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated
