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

exec with wildcards

1,852 views
Skip to first unread message

Martin

unread,
May 5, 1998, 3:00:00 AM5/5/98
to

hello,

the following statement doesnt work :

catch { exec rm /tmp/1998* & } result

rm echos to stdout :

rm: /tmp/1998* : No such file or directory

The files 1998* really exist in the tmp directory.
I think it has something to do with the wildcard because without
wildcards it's working.

Thanks a lot.

Martin


Benjamin Riefenstahl

unread,
May 5, 1998, 3:00:00 AM5/5/98
to

Hi Martin,


Martin wrote:
> catch { exec rm /tmp/1998* & } result
>
> rm echos to stdout :
>
> rm: /tmp/1998* : No such file or directory
>
> The files 1998* really exist in the tmp directory.
> I think it has something to do with the wildcard because without
> wildcards it's working.

You mean files that match that wildcard spec exist in /tmp. Wildcard
expansion is done by the shell in Unix. As you are not using a shell in
your snippet you don't get wildcard expansion. Try

exec sh -c rm /tmp/1998* &

or, to use Tcl's internal wildcard expansion service

exec rm [glob /tmp/1998*] &


so long, benny
======================================
Benjamin Riefenstahl (be...@crocodial.de)
Crocodial Communications EntwicklungsGmbH
Ruhrstraße 61, D-22761 Hamburg, Germany

D. Richard Hipp

unread,
May 5, 1998, 3:00:00 AM5/5/98
to Martin

Martin wrote:
> the following statement doesnt work :
>
> catch { exec rm /tmp/1998* & } result
>
> rm echos to stdout :
>
> rm: /tmp/1998* : No such file or directory
>

In UNIX, Wildcards are normally expanded by your shell. But
"wish" and "tclsh" don't expand wildcards unless you tell them
to.

You can accomplish your goal in several ways:

eval exec rm [glob /tmp/1998*]

Or

exec /bin/sh -c "rm /tmp/1998*"

Or

eval file delete [glob /tmp/1998*]

Some or all of the above will fail if no files match
the pattern /tmp/1998* or if any of the files contain
spaces in their names. The following version is
more robust:

foreach file [glob -nocomplain /tmp/1998*] {
file delete $file
}

--
D. Richard Hipp -- d...@acm.org -- http://www.hwaci.com/drh/

Christopher Nelson

unread,
May 5, 1998, 3:00:00 AM5/5/98
to Martin

Martin wrote:
> the following statement doesnt work :
>
> catch { exec rm /tmp/1998* & } result
>
> rm echos to stdout :
>
> rm: /tmp/1998* : No such file or directory

Check out:

http://starbase.neosoft.com/%7Eclaird/comp.lang.tcl/fmm.html#ls


--
Rens-se-LEER is a county. RENS-se-ler is a city. R-P-I is a school in
Troy!

Eric Galluzzo

unread,
May 5, 1998, 3:00:00 AM5/5/98
to

Benjamin Riefenstahl wrote:

> Try
>
> exec sh -c rm /tmp/1998* &
>
> or, to use Tcl's internal wildcard expansion service
>
> exec rm [glob /tmp/1998*] &

Or you could remove the exec entirely:

set files [glob -nocomplain /tmp/1998*]
if {![string compare $files {}]} {
eval file delete $files
}

The following is more concise, but less safe: it assumes that glob returns
the error, not file delete, and that the error returned from glob is that
nothing matched the given pattern:

catch {eval file delete [glob -- /tmp/1998*]}

By the way, these replacements both require (I believe) Tcl 7.5.

Hope that helps. :)

- Eric

--
----=--=-=-==-===-=====//=====\\=====-===-==-=-=--=-----------------------
"God is real, unless // Name: \\ Eric Galluzzo | Software Engineer | SDRC
declared integer." // E-mail: \\ Eric.G...@sdrc.com
// SDRC WWW: \\ http://www.sdrc.com/
-- Unknown // http://www.geocities.com/SiliconValley/Vista/5567/
--=-=-==-===-=====//===============\\=====-===-==-=-=--=------------------


0 new messages