1

I have a shell command which find files that contain 2 strings together:

$ grep -rl JFL . 2>/de/null | while read n; do grep -l 20120907 "$n"; done

The strings above are JFL and 20120907

Now I would like to set it as an alias, like below:

mysearch JFL 20120907

How can I create this alias?

1 Answer 1

3

add to your ~./bashrc the following:

mysearch () {
      grep -rl "$1" . 2>/dev/null | while read n; do grep -l "$2" "$n"; done
}

This defines the function that became available as a command at the bash prompt. All arguments to the functions in bash are expanded as $1, $2,... like arguments to the scripts. When editing your .bashrc do not forget to restart bash (re-login), as bash read this file when it starts.

1
  • Functions are far better than aliases on several different levels. Listen to Serge and you'll go far. Oct 2, 2012 at 20:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .