1

I am trying to create a function that will take the parameters that I pass it and do a grep search in my current directory, but I can't figure out how to use all the parameters as one string.

Here is what I have:

search()
{
  clear
  grep -rnw . -e $("\"" $@ "\"")
}

So if I were to type, search title =, I would want it to do grep -rnw . -e "title ="

Any ideas for how to do this?

1
  • how do would I make it so I can use other characters without quotes? such as > or " or other escape characters? Commented Jun 24, 2015 at 21:29

1 Answer 1

1

Use "$*" if you want all passed arguments as a single string:

search() {
  clear
  grep -rnw "$*" .
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.