[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ find-grep-dired ] Regexp input and other remarks
From: |
Fabrice Bauzac |
Subject: |
[ find-grep-dired ] Regexp input and other remarks |
Date: |
Sat, 02 Mar 2002 20:02:50 +0100 |
Good evening everyone,
I used the find-grep-dired command to search for files matching a
regular expression. My regular expression was simple: it was the
string `2.4.12'. Since find-grep asked for a regexp:
Find-grep (grep regexp):
I entered:
2\.4\.12
so that the dots aren't interpreted by grep as the all-matching
character. But the commandline sent to the shell seems to not quote
special characters, because here is the result of find-grep:
~/linux-2.4.12/:
find . \( -type f -exec grep -q 2\.4\.12 {} \; \) -exec ls -ld {} \;
-rw-r--r-- 1 noon noon 359166 mar 7 2001
drivers/net/dgrs_firmware.c
[...]
The files don't contain the _string_ `2.4.12' (at least, not the first
file). But the first file contains strings such as `254,128' which
match the regexp /2.4.12/.
Moreover, if the user inserts an unquoted space, `grep' recieves
several arguments, and that isn't a proper behaviour. If the user
inserts the string {}, or if there is a leading dash (which will be
interpreted as the start of a switch by grep), too. In fact there are
quite many situations where one can't just put a normal regular
expression at the find-grep prompt.
One workaround would be to quote the regexp with single quotes '' at
the `Find-grep (grep regexp):' prompt.
But I think it would be more user-friendly if it was GNU Emacs that quoted
the user's string:
* Replace every _'_ with _'\''_
* Put an initial and a final quote _'_
* Use -q -e as arguments to `grep' instead of just -q, in order to
prevent the "leading dash" interpretation.
But if GNU Emacs does that, there are possible problems, including:
* No compatibility with previous GNU Emacs versions (but it is
possible to use another name for the modified command, thus leaving
find-grep with its current behaviour).
* Maybe shell dependance (I don't know the UNIX shells that are not
Bourne: maybe the character _'_ does not have the same
meaning/behaviour). Maybe Emacs could explicitely run /bin/sh.
* Maybe dependance for the version of grep concerning the -e switch
(i.e. I don't know whether all the grep programs understand the
meaning of that switch).
Maybe this has been previously discussed? Sorry if it is the case.
Have a nice weekend.
--
fabrice bauzac
Software should be free. http://www.gnu.org/philosophy/why-free.html
- [ find-grep-dired ] Regexp input and other remarks,
Fabrice Bauzac <=