2

I have a question regarding the creation of a utility that executes another command.

My script called notify will be placed in my /usr/local/bin directory and will do the following:

Execute the command that it was told to execute, then play a beep.

An example use case is the following:

> notify grep -r "hard_to_find_word" /some/huge/directory/

This is just an example, but could involve some other slower commands.

Essentially, notify will execute the grep, and then play a sound.

I know how to play a sound, but I do not know how to execute the provided command.

How do I execute the command that follows the call of notify?

Thank you for any input!

3
  • Also, don't abuse the word "function"; it has a specific meaning in bash, which neither of these are. Commented Mar 19, 2012 at 22:59
  • Sorry! I was a little confused about that but wasn't sure. So this would be more of a utility, correct? Commented Mar 19, 2012 at 23:14
  • Okay, I'll use the word command from now on. Thanks! Commented Mar 19, 2012 at 23:19

1 Answer 1

5

"$@" is all the arguments properly separated.

"$@"
Sign up to request clarification or add additional context in comments.

4 Comments

Oh! That is great! I knew that $@ provides all the parameters, but I didn't know that you could just call it by itself! Thank you!
@Kaushik , play close attention to the use of quotes here -- very important.
Hmm I tried it with and without quotes and it seems to be working the same. What do the quotes do?
The quotes make sure that arguments containing whitespace are handled properly.

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.