How do I write an alias for grep -R?

前端 未结 2 1886
慢半拍i
慢半拍i 2021-02-05 13:31

I end up typing

grep -Rni pattern .

and awful lot. How do I make this into an alias like

alias gr=\'grep -Rni $@ .\'

相关标签:
2条回答
  • 2021-02-05 14:10

    make a function instead of alias. Save it in a file eg mylibrary.sh and whenever you want to use the function, source the file

    eg mylibrary.sh

    myfunction(){
     grep -Rni ...
    }
    
    #!/bin/bash
    source mylibrary.sh
    myfunction 
    
    0 讨论(0)
  • 2021-02-05 14:30

    Try this:

    $ alias gr='grep -Rnif /dev/stdin . <<<'
    $ gr pattern
    ./path/file:42:    here is the pattern you were looking for
    

    This also works:

    $ alias gr='grep -Rnif - . <<<'
    
    0 讨论(0)
提交回复
热议问题