linux - How do I shorten this grep command? -


i want grep command shorter, e.g., able type g on command line execute grep options -pei.

i've tried alias in bash, piping doesn't work.

 alias g='grep --color auto -pei' 

gives me

 history |g qemu  grep: auto: no such file or directory  grep: qemu: no such file or directory 

i tried in .bashrc

 function g () { /bin/grep -pei "$@" ;} 

it still outputs

 history |g qemu  grep: qemu: no such file or directory 

there 2 separate problems alias:

  • long-form gnu options (those starting -- rather -) require = between option name , value (argument):

    • i.e., should --color=auto, not --color auto
  • you're using option -e incorrectly: purpose accept multiple search patterns, each -e instance requiring argument - in case, [-]e directly followed i, therefore mistakenly serves -e's argument, i.e., pattern, causing true search pattern misinterpreted filename operand.

thus, redefine alias follows:

alias g='grep --color=auto -pi' 

update: tripleee's answer implies, using -e has 1 advantage: allows specify patterns start - without getting misinterpreted further options; thus, placing -e last in alias give advantage.

alias g='grep --color=auto -pie' 

of course, not building -e alias leaves option specify on demand, when invoking alias, make use of multiple -e options more intuitable.


finally, advice given @thatotherguy in comment worth heeding:

before defining alias, make sure definition works expected directly entered command.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -