Re: Regexes on the command line
- From: Tom Anderson <twic@xxxxxxxxxxxxxxx>
- Date: Thu, 26 Feb 2009 23:32:39 +0000
On Thu, 26 Feb 2009, Tom McGlynn wrote:
On Feb 26, 4:40 pm, Tom McGlynn <t...@xxxxxxxxxxxxxxxxxxxxxx> wrote:On Feb 26, 2:52 pm, Tom Anderson <t...@xxxxxxxxxxxxxxx> wrote:On Thu, 26 Feb 2009, Tom McGlynn wrote:
where match is a little shell script
#!/bin/bash
java -cp ... somepackage.Match $*
When the java command inside the script executes it reanalyzes the command string and since the single quotes are gone it misinterprets the special characters. There are a number of ways to address this. You can use aliases rather than scripts, but that's a bit limiting. You could use Perl and do a multi-argument system call (I presume there are equivalents in Python, Ruby and elsewhere) which doesn't re- analyze the arguments. What I've tended to do is to analyze the input arguments and regenerate the command line in the script requoting any special characters.
java Match '$*' doesn't do it for you? Or better yet, IMHO, '$@'.
Thanks... That's not quite right but I think you just misremembered
it.
It should be
java Match "$@"
Once you pointed me to the proper variable I was able to see it in the
bash documentation.
I should probably have phrased this a little more cautiously but I was in a hurry. The other Tom clearly is more familiar than I with this, but at last on my machine '$*' and '$@' are not expanded by bash. Possibly they are in some of the other shells.
Argh! No, you're quite right, and i wasn't thinking straight. I had the idea that they'd both be expanded, but with different amounts of expansion of shell variables in them, but of course neither of them do any expansion of anything inside the string. '' just quotes, and "" expands the variable into a quoted string.
The funny thing is that i've spent the last week or two doing almost nothing but shell, so you'd have thought i'd be on top of this. Maybe i've gone snowblind instead.
"$*" expands as a single argument, so it doesn't quite do what I typically want. But "$@" is very very nice!
"$@" is a fine invention. I'm not really sure what the use of "$*" is!
tom
--
eggflip, brandy, bits of Tia Maria, Beecham's powder, aspirin,
Benedictine, Alka-Seltzer, black currant juice, a touch of mustard and
"other things"
.
- Follow-Ups:
- Re: Regexes on the command line
- From: Martin Gregorie
- Re: Regexes on the command line
- References:
- Regexes on the command line
- From: Roedy Green
- Re: Regexes on the command line
- From: Tom McGlynn
- Re: Regexes on the command line
- From: Tom Anderson
- Re: Regexes on the command line
- From: Tom McGlynn
- Re: Regexes on the command line
- From: Tom McGlynn
- Regexes on the command line
- Prev by Date: Re: 0x5DEECE66DL + 0xBL. Why?
- Next by Date: Re: BigInteger enhancing
- Previous by thread: Re: Regexes on the command line
- Next by thread: Re: Regexes on the command line
- Index(es):
Relevant Pages
|