Re: Variables containing regular expressions
From: Netocrat (netocrat_at_dodo.com.au)
Date: 06/19/05
- Next message: Netocrat: "Re: Variables containing regular expressions"
- Previous message: Janis Papanagnou: "Re: what is the command to kill suspended job"
- In reply to: flatlineato: "Variables containing regular expressions"
- Next in thread: Netocrat: "Re: Variables containing regular expressions"
- Reply: Netocrat: "Re: Variables containing regular expressions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 19 Jun 2005 22:07:58 +1000
On Sun, 19 Jun 2005 11:21:54 +0200, flatlineato wrote:
This is appropriate - just yesterday I was commenting that special
characters and quoting is the shell's way of keeping you on your
toes. Well let's see how my toes are doing...
The simplest way to see what's going on is to prepend your final command
with an echo:
$ REGEX="'search_by_.*'"
$ ARGS="-exec grep -l ${REGEX} {} \;"
$ echo find ./ ${ARGS}
find ./ -exec grep -l 'search_by_.*' {} \;
Well that's interesting. After all shell parsing, we discover that grep
is searching for the literal string
'search_by_.*'
instead of the regexp
search_by_.*
and that find is seeing an escaped semicolon rather than a semicolon.
So the solution - remove the inner single quotes in the REGEX assignment:
$ REGEX="search_by_.*"
and as you already discovered, "remove the ; escaping":
$ ARGS="-exec grep -l ${REGEX} {} ;"
Now let's test:
$ echo find ./ ${ARGS}
find ./ -exec grep -l search_by_.* {} ;
That looks more like it. Let's run without the echo:
$ echo search_by_.blah>testfile
$ find ./ ${ARGS}
./testfile
Now I don't have dialog installed on my system but it looks to me that the
only change you need to make to your script should be:
> ARGS="${ARGS} -exec grep -l ${REGEX} {} \;"
Don't quote the semicolon:
ARGS="${ARGS} -exec grep -l ${REGEX} {} ;"
If that doesn't work then give us a cat of ${TMPFILE_CONT} as I may not
have properly guessed what it would do.
- Next message: Netocrat: "Re: Variables containing regular expressions"
- Previous message: Janis Papanagnou: "Re: what is the command to kill suspended job"
- In reply to: flatlineato: "Variables containing regular expressions"
- Next in thread: Netocrat: "Re: Variables containing regular expressions"
- Reply: Netocrat: "Re: Variables containing regular expressions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|