From jwe at bevo.che.wisc.edu  Wed Nov 26 15:36:44 2003
From: jwe at bevo.che.wisc.edu (John W. Eaton)
Date: Wed Nov 26 15:35:43 2003
Subject: [Rd] Question about Unix file paths
In-Reply-To: <16324.41500.528451.479889@gargle.gargle.HOWL>
References: <17b5svs7cl2cjmto222665p545mb0ok74u@4ax.com>
	<Pine.LNX.4.44.0311250728180.26806-100000@gannet.stats>
	<16324.27878.740145.101@mithrandir.hornik.net>
	<16324.41500.528451.479889@gargle.gargle.HOWL>
Message-ID: <16324.47740.655303.232180@devzero.bogus.domain>

On 26-Nov-2003, Martin Maechler <maechler@stat.math.ethz.ch> wrote:

| >>>>> " Kurt" == Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
| >>>>>     on Wed, 26 Nov 2003 10:05:42 +0100 writes:
| 
|      Kurt> Right.  In any case, an explicit glob() function
|      Kurt> seems preferable to me ...
| 
| Good idea!
| 
| More than 12 years ago, I had a similar one, and wrote  a
| "pat2grep()" {pattern to grep regular expression} function
| --- for S-plus on Unix ---  which I have now renamed to  glob2regexp():
| -- still not really usable outside unix (or windows with the
| 'sed' tool in the path), nor perfect, but maybe a good start:
| 
| sys <- function(...) system(paste(..., sep = ""))
| 
| glob2regexp <- function(pattern)
| {
|   ## Purpose: Change "ls pattern" to "grep regular expression" pattern.
|   ## -------------------------------------------------------------------------
|   ## Author: Martin Maechler ETH Zurich, ~ 1991
|   sys("echo '", pattern, "'| sed ",
|       "'s/\\./\\\\./g;s/*/.*/g;s/?/./g; s/^/^/;s/$/$/; s/\\.\\*\\$$//'")
| }

It seems to me that using this approach to implement a proper glob()
function would be more work than using the glob code that is available
as part of bash, which I think will allow you to handle much more
complex patterns, including [xyz] {a,b,c} etc.

jwe


[Rd] Question about Unix file paths
John W. Eaton