| delorie.com/archives/browse.cgi | search |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sources.redhat.com/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
| Message-Id: | <5.1.0.14.2.20020802162547.035e9a58@pop3.cris.com> |
| X-Sender: | rrschulz AT pop3 DOT cris DOT com |
| Date: | Fri, 02 Aug 2002 16:31:13 -0700 |
| To: | "Barnhart, Kevin" <Kevin DOT Barnhart AT echostar DOT com>, |
| "'cygwin AT cygwin DOT com'" <cygwin AT cygwin DOT com> | |
| From: | Randall R Schulz <rrschulz AT cris DOT com> |
| Subject: | Re: Easy, quick, BASH question |
| In-Reply-To: | <C69F6A9E1E1F5A488C58B168F0875F4006B80CAB@riv-exch1.echosta |
| r.com> | |
| Mime-Version: | 1.0 |
Kevin,
In BASH aliases are much more limited than they are in CSH/TCSH. BASH
aliases can only perform a left-hand substitution for the aliased command.
It can be a multi-word substitution, but the alias is a completely
unparameterized substitution and the substitution remains strictly at the
left of the resulting command with any arguments passed to the alias added
on the right / after those appearing in the alias definition.
To get anything more complicated, you must use a shell procedure. E.g.:
hcgrep() {
grep -n "$@" $(find -name '*.[ch]')
}
Note that you want to use "$@" not "$*" since the former yields each
argument individually quoted whereas the second produces a single argument
to grep consisting of each argument to chgrep concatenated with a single
space interpolated between each.
Randall Schulz
Mountain View, CA USA
At 15:04 2002-08-02, Barnhart, Kevin wrote:
>I'm trying to setup an alias for grep that recursively looks through all .c
>and .h files for a string. So far I've tried variations of:
>
>alias hcgrep='grep -n "$*" $(find . -name '*.[ch]')'
>
>There's probably just one little thing I'm missing...
>
>Thanks,
>Kevin
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |