4

I have this as a bash function:

function gits() {
  git grep -i -n --color $@ -- $(git rev-parse --show-toplevel);
}

If I run this:

gits def add_crumb

I want:

git grep -i -n --color "def add_crumb" -- $(git rev-parse --show-toplevel)
Lesmana
  • 25,663
  • 9
  • 82
  • 87
ibash
  • 1,477
  • 17
  • 31
  • 3
    See [How to iterate over arguments in bash script](http://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-bash-script/256225#256225) for an extensive discussion of `$@` vs `$*` vs `"$@"` vs `"$*"`. – Jonathan Leffler Aug 28 '11 at 19:34

1 Answers1

10

The purpose of $@ is specifically to split it into individual arguments. Use "$*" if you don't want that. (Yes, with the double quotes; you should have them in "$@" as well, actually.)

fejese
  • 4,601
  • 4
  • 29
  • 36
tripleee
  • 175,061
  • 34
  • 275
  • 318