[oclug] OT: tcl question
Patrick Smith
patsmith at pobox.com
Sat Mar 16 12:21:28 EST 2002
Joe Burpee wrote:
> I think `concat' would have a similar effect and make the
> `eval' relatively safe. It strips off at most one level of nesting so
> it preserves the args as separate words.
>
> eval exec [concat ls -l $dirs]
But concat doesn't process the elements of the lists that are its
arguments. So how is the above different from
eval exec ls -l $dirs
?
For example:
% set dirs "a ; b"
a ; b
% concat ls -l $dirs
ls -l a ; b
On the other hand, lappend does escape list elements. So to make an
arbitrary list safe for eval you could do something like this:
> touch a \; b
> tclsh
% set dirs "a ; b"
a ; b
% set args {}
% foreach d $dirs {lappend args $d}
% set args
a {;} b
% eval exec ls -l $args
-rw-r--r-- 1 pat pat 0 Mar 16 12:19 ;
-rw-r--r-- 1 pat pat 0 Mar 16 12:19 a
-rw-r--r-- 1 pat pat 0 Mar 16 12:19 b
--
patsmith at pobox.com
More information about the OCLUG
mailing list