Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass $@ as a single argument to another command in a bash function?

Tags:

bash

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)
like image 305
ibash Avatar asked Dec 28 '22 15:12

ibash


1 Answers

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.)

like image 190
tripleee Avatar answered May 11 '23 01:05

tripleee