Mailinglist Archive: opensuse (2740 mails)
| < Previous | Next > |
Re: [opensuse] bash - handling expansion of parameters on the command line?
- From: Randall R Schulz <rschulz@xxxxxxxxx>
- Date: Mon, 1 Dec 2008 21:06:33 -0800
- Message-id: <200812012106.34110.rschulz@xxxxxxxxx>
On Monday 01 December 2008 18:25, David C. Rankin wrote:
In limited circumstances you can, but I'm guessing they're not the ones
you want.
The only option you have in BASH is whether a wild-card that does _not_
match any files is treated as an error or passed unaltered. I prefer
the latter, 'cause then you can do things like this:
% egrep -Rl --include=*.java pattern files-and-dirs
without quoting the argument and not get an error (and pretty much
always count on that wildcard _not_ matching, which is of course what I
want). This is probably a pretty good analog for your case. Egrep
itself (as it Recursively traverses the directories given) will look at
only those files that match one of the --include= patterns (and does
not match one of the --exclude= patterns).
However, if you want a pattern that _does_ match to still be passed
unaltered, you're out of luck. There's nothing corresponding to control
over argument expansion in BASH other than quoting the arguments.
However, if you're willing to do something along these lines (as in the
aforementioned egrep example or as dd does with arg=value format), then
you've got something to work with.
The preferred colloquialism is "skin that rat."
Randall Schulz
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
Bash wizards:
I have run across another quandary. I am trying to get a filespec
from the command line like:
./scriptname file1*
and file name expansion occurs before I can assign the filespec to a
variable. I want to be able to grab the 'file1*' filespec without
having to require that it be enclosed in single quotes (./scriptname
'file1*'). I'm using the filespec like:
In limited circumstances you can, but I'm guessing they're not the ones
you want.
The only option you have in BASH is whether a wild-card that does _not_
match any files is treated as an error or passed unaltered. I prefer
the latter, 'cause then you can do things like this:
% egrep -Rl --include=*.java pattern files-and-dirs
without quoting the argument and not get an error (and pretty much
always count on that wildcard _not_ matching, which is of course what I
want). This is probably a pretty good analog for your case. Egrep
itself (as it Recursively traverses the directories given) will look at
only those files that match one of the --include= patterns (and does
not match one of the --exclude= patterns).
However, if you want a pattern that _does_ match to still be passed
unaltered, you're out of luck. There's nothing corresponding to control
over argument expansion in BASH other than quoting the arguments.
However, if you're willing to do something along these lines (as in the
aforementioned egrep example or as dd does with arg=value format), then
you've got something to work with.
... What is the best way to skin this cat? ...
The preferred colloquialism is "skin that rat."
Thanks.
--
David C. Rankin
Randall Schulz
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
| < Previous | Next > |