Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using asterisk with exec command

801 views
Skip to first unread message

shady_abdelwahed

unread,
May 10, 2009, 11:59:48 AM5/10/09
to
Hi,

I wanted to pass the results of an "ls" command to a certain variable.
So, I used the following syntax:

set x [exec ls *.tcl]

But, unfortunately it didn't work. And, when I viewed some examples
for "exec" command on the web, I found I should write it in the
following syntax:

set x [exec ls {*} [glob *.tcl]]

Can any one explain to me why using the asterisk wild card with "exec"
required to write this command like that instead of the first command
I wrote above?

Uwe Klein

unread,
May 10, 2009, 12:24:49 PM5/10/09
to

usually you get the "glob"ing from the shell. ( but find forex has its own globing )

In your case the following would be sufficient

set x [exec ls [glob *.tcl]]

as an alternative you can exec the shell to run your ls command:

exec $::env(SHELL) -c {ls -l *}

now try find:

exec find . -name * -printf {%m %n % 8s %u %g %p \n}

uwe

Glenn Jackman

unread,
May 10, 2009, 1:19:21 PM5/10/09
to
At 2009-05-10 11:59AM, "shady_abdelwahed" wrote:
> set x [exec ls {*} [glob *.tcl]]

Take care with the {*} syntax: no space between the splat and the list
being expanded:

set x [exec ls {*}[glob *.tcl]]

--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous

Uwe Klein

unread,
May 10, 2009, 2:37:30 PM5/10/09
to
Glenn Jackman wrote:
> At 2009-05-10 11:59AM, "shady_abdelwahed" wrote:
>
>> set x [exec ls {*} [glob *.tcl]]
>
>
> Take care with the {*} syntax: no space between the splat and the list
> being expanded:
>
> set x [exec ls {*}[glob *.tcl]]
>
Ups, sometimes one is so sure ...
nix the first script line in my initial reply to the OP


uwe

Gerald W. Lester

unread,
May 10, 2009, 3:07:22 PM5/10/09
to
shady_abdelwahed wrote:
> Hi,
>
> I wanted to pass the results of an "ls" command to a certain variable.
> So, I used the following syntax:
>
> set x [exec ls *.tcl]

Others have explained about globing being a shell property.

I'd like to point out you do not need exec or ls at all, you could just do:

set x [glob *.tcl]

If you want any of the details that some of the switches to ls provide, you
can get them via the file command.


--
+------------------------------------------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

bi...@rocketship1.biz

unread,
May 10, 2009, 6:18:12 PM5/10/09
to
On May 10, 10:19 am, Glenn Jackman <gle...@ncf.ca> wrote:

> Take care with the {*} syntax: no space between the splat and the list
> being expanded:

Ahhhh, yes, this new feature.... Can someone provide a link to the
description of this newish tcl feature, as all the searching I've
tried using all varieties of {*} have not worked for me.

I understand it's basic idea, I just can't find the syntax rules, such
as the statement above saying it can't have spaces.....

thanks

Bryan Oakley

unread,
May 10, 2009, 10:39:32 PM5/10/09
to

It's in the Tcl(n) man page:

http://tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M9

0 new messages