0

I'm trying to write a function that will find all processes by name and then let you send signals to them one by one. Here is the smallest part of code that I can't get to work correctly:

ps -ef | grep "$@"

If I used

ab cd

as the input to the function, I'd like it to generate

ps -ef | grep "ab cd"

but instead it generates

ps -ef | grep ab cd

which looks for 'ab' in the file 'cd'.

1 Answers1

2

You want "$*", not "$@". This answer goes into details, but basically "$@" quotes each parameter individually, while "$*" quotes the whole mess. So, "$@" is equivalent to "ab" "cd"; "$*" is equivalent to "ab cd".

Community
  • 1
  • 1
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • Thank you. I tried so hard to search for the proper stack overflow response (I knew someone must have asked something like this before) but I couldn't find it. – AndrewLngdn Jan 08 '15 at 18:40