grep is one of the most commonly used command in linux. It feels to me that its basic feature to highlight the string you searched for on the output lines. this can be achieved by --color option.
Typing --color every single time is annoying and also not productive. Is there any way to change grep to behave as grep --color.
I tried writing a small script named it grepd and added this to my PATH variable. But the script doesnt work on the input grepd . Any suggestions please.
#!/bin/bash
grep --color $1 $2
alias
option in the accepted answer is probably really the way to go, I'm guessing that the problem you had here was primarily one related to the way you used positional parameters ($1
and$2
). A better option for the second line of this script would have been:grep --color "$@"
--$@
, when in double-quotes ("
) specifically, will expand to the list of arguments the script was passed with, and in the same manner... so for example, if a*
is in your grep pattern (e.g..*
), that won't expand, and would be passed on to grep... among other things.