Last active
April 19, 2016 12:29
-
-
Save ysf/50d50902e015b8cd3c30c6eb1f34913a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # source from .bashrc for lazy pipe grep magic | |
| command_not_found_handle () | |
| { | |
| # only run within an input pipe | |
| if [[ -p /dev/stdin ]]; then | |
| grep -- "$*" | |
| return $? | |
| fi | |
| echo $"$1: command not found" | |
| return 127 | |
| } |
Author
Yeah, thanks a lot @algorythmic. From time to time, I still use the args passing feature, but if i really need those I can still pipe and call grep directly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You prob only want to pass one argument to
grep-- the string to search for. With"$@"you pass all the original args separately, so if you had more than one word they would be interpreted as file names to look in. I think"$*"makes more sense so you pass just one single arg to grep consisting of all the words you had after the pipe.Also makes sense to pass
--first in case your string starts with a hyphen -- this way it won't be treated as an arg.So like
grep -- "$*"