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
  • 24,114
  • 8
  • 78
  • 84
ibash
  • 1,431
  • 16
  • 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,481
  • 4
  • 27
  • 36
tripleee
  • 158,107
  • 27
  • 234
  • 292