Ziu
Ziu

Reputation: 659

how to combine mutiple command as one by a function?

I have often using some combined command like find . -name *.rb -print|xargs grep -n --color=auto current or history|grep xx or else. So, how to write a function, say 'anfind', and i can call it with two arguments,'rb' and 'current', then it can display the result ? like this:

$ anfind
  (wait for two arguments) rb help
  (display)result

Thanks

Upvotes: 1

Views: 45

Answers (1)

Josh Jolly
Josh Jolly

Reputation: 11796

Define your own function inside your .profile or .bashrc file like this (or within a script):

anfind() {
    find . -name ...etc
}

Then within your function, you can use arguments with $1, $2, etc. An example:

echo_args() {
    echo "First arg: $1 - Second arg: $2"
}

$ echo_args Hello world
First arg: Hello - Second arg: world

Upvotes: 1

Related Questions