|
|
Ignore grep command self-match
One of the advantages of the original hint is that it avoids the second grep process in the pipeline. However, its form, which requires separating the first letter from the others, makes difficult to embed in an alias. This is why the other suggestions go back to the two-process pipeline.
However, the general principle is that the regular expression not match its invocation. Since the names of programs are always "words" in the regular expression sense, there is another way to use the basic principle of the original hint, but which allows easy use in an alias: explicitly match the word boundary using the \b regular expression substring. This results in a command for the original example, and since it is trivial to precede any string with \b or \b depending on the quote level, this can be used easily in a shell function or script:
Note that this can't be an alias because "$1" expands to " $1" when aliases are expanded, with an added space that messes up the regular expression. But functions work fine.
Greg Shenaut |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.14 seconds |
|